animal

多态与鸭子和反射

一个人想着一个人 提交于 2019-12-06 12:46:48
一、多态 1.什么是多态? 多态指同一类型的事物的,不同形态。 2.多态的目的: 多态也称之为多态性,目的是为了在不知道对象具体类型的情况下统一对象🙆调用方法的规范。 多态的表现形式之一就是继承: 先抽象,再继承。 父类:定制一套统一的规范。 子类:遵循父类的统一的的规范。 注意:在python中不会强制限制子类必须遵循父类的规范,所以出现了抽象类。 class Animal: def eat(self): pass​ def speak(self): pass​​class Pig(Animal): def eat(self): print('一口没')​ def speak(self): print('哼哼哼')​​class Cat(Animal): def eat(self): print('慢慢吃') def speak(self): print('喵喵喵')​​class Dog(Animal): def eat(self): print('还有吗') def speak(self): print('汪汪汪')​animal = Pig()animal1 = Cat()animal2 = Dog()​animal.eat()animal1.eat()animal2.eat()​animal.speak()animal1.speak()animal2.speak(

28.Java基础_抽象类

纵饮孤独 提交于 2019-12-06 10:52:33
抽象类的成员特点 1 public abstract class Animal { 2 private String name; 3 private int age; 4 public Animal() { 5 } 6 public Animal(String name, int age) { 7 this.name = name; 8 this.age = age; 9 } 10 public String getName() { 11 return name; 12 } 13 public void setName(String name) { 14 this.name = name; 15 } 16 public int getAge() { 17 return age; 18 } 19 public void setAge(int age) { 20 this.age = age; 21 } 22 public abstract void eat(); 23 } 24 25 26 public class Cat extends Animal{ 27 public Cat() { 28 } 29 public Cat(String name, int age) { 30 super(name, age); 31 } 32 @Override 33 public void

python之多态、抽象类、鸭子类型

风格不统一 提交于 2019-12-05 23:45:38
''' 1.什么是多态? 多态指的是同一类型的事物,不同的表现形式。 2.多态的目的: 多态 也称为多态性,目的是为了在不知道对象的具体类型的情况下,同一调用属性或方法的规范。 继承是实现多态的方法之一。 - 先抽象,再继承 父类:定制一套统一的规范 子类:遵循父类统一的规范。 注意:再python中不会强制限制子类必须遵循父类的规范。(要引入抽象类) ''' class Animal: def eat(self): pass def bark(self): pass class Tiger(Animal): def eat(self): print(self.__class__.__name__, 'is eating something') def bark(self): print(self.__class__.__name__, 'is barking...') class Cat(Animal): def eat(self): print(self.__class__.__name__, 'is eating something') def bark(self): print(self.__class__.__name__, 'is barking...') class Lion(Animal): def eat(self): print(self.__class__._

The Illustrated Transformer

别来无恙 提交于 2019-12-05 21:48:53
摘自 Jay Alammar https://jalammar.github.io/illustrated-transformer/ The Illustrated Transformer In the previous post, we looked at Attention – a ubiquitous method in modern deep learning models. Attention is a concept that helped improve the performance of neural machine translation applications. In this post, we will look at The Transformer – a model that uses attention to boost the speed with which these models can be trained. The Transformers outperforms the Google Neural Machine Translation model in specific tasks. The biggest benefit, however, comes from how The Transformer lends itself to

面向对象基础(二)

橙三吉。 提交于 2019-12-04 11:01:25
# 例:# 写三个类: 狗,猫,鸡, 每个类中都有 吃 喝 自己的方法 最后定义一个Animal类, class Animal: def __init__(self,name,sex,age): self.name = name self.sex = sex self.age = age def eat(self,option): print('%s 在吃 %s' %(self.name,option)) def drink(self,option): print('%s 在喝 %s' %(self.name,option)) # 以下两个类继承了Animal class Cat(Animal): def miaow(self): print('MM') class Person(Animal): def work(self): print('Working') c1 = Cat('MM','Wom','Tom') c1.eat('鱼') # result:MM 在吃 鱼 # 可以根据查找链获取到继承来的字段和方法包括构造函数 # 只执行父类的方法:子类中不要定义与父类同名的方法 # 只执行子类的方法:在子类创建这个方法. # 那么如果我们既要执行子类又要继承父类呢?比如Cat类的实例需要一个特殊的属性hair class Cat(Animal): def __init__

python_面向对象——继承

与世无争的帅哥 提交于 2019-12-04 10:21:12
1.继承 class Animal: def __init__(self,name,age,sex): self.name = name self.age = age self.sex = sex def eat(self): print('{}正在吃东西~'.format(self.name)) # 继承(Animal)类 class Person(Animal): def talk(self): print('子类独有的方法!') # 子类可以使用父类中的方法 p = Person('yhf',23,'女') p.eat()   子类也可以继承父类的属性: class Animal: a_type = '动物' def __init__(self,name,age,sex): self.name = name self.age = age self.sex = sex def eat(self): print('{}正在吃东西~'.format(self.name)) # 继承(Animal)类 class Person(Animal): def talk(self): print('独有的方法!') p = Person('yhf',23,'女') # 子类也可以继承父类的属性 print(p.a_type) 2.重构父类中的方法 class Animal: def _

继承和单继承

随声附和 提交于 2019-12-04 09:20:57
#狗 吃 喝 拉撒 游泳#鸟 吃 喝 拉撒 下单# class Animal:# def __init__(self):# print("执行Animal__init__")# self.func()# def eat(self):# print("%s eating"%self.name)# def drink(self):# print("%s drinking"%self.name)# def func(self):# print("Animal.func")# class Dog(Animal):# def guard(self):# print("guarding")# def func(self):# print(Dog.func)# dog=Dog()# class A:# pass# class B:# pass# class A_son(A,B):# pass# class AB_son(A):# pass# print(A.__bases__)# print(B.__bases__)# print(AB_son.__bases__)# print(A_son.__bases__)# class Animal:# def __init__(self, name ,hp ,aggr):# self .name=name# self.blood =hp# self

[Dart] Mixin

随声附和 提交于 2019-12-03 15:08:54
Docs Mixins are a way of reusing a class’s code in multiple class hierarchies. void main() { Animal animal = Animal(); Bird().fly(); Fish().swim(); Duck().move(); Duck().swim(); Duck().fly(); } mixin CanSwim { void swim() { print('change poisiton by swimming'); } } mixin CanFly { void fly() { print('change poisiton by flying'); } } class Animal { void move () { print('change position'); } } class Fish extends Animal with CanSwim{ @override void move () { super.move(); } } class Bird extends Animal with CanFly{ @override void move () { super.move(); } } class Duck extends Animal with CanFly,

Saving blobs with Google Endpoint

匿名 (未验证) 提交于 2019-12-03 08:51:18
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an app that allows users to save blobs in the blobstore. I have a schema that does so presently, but I am interested in something simpler and less twisted. For context, imagine my app allows users to upload the picture of an animal with a paragraph describing what the animal is doing. Present schema User calls my endpoint api to save the paragraph and name of the animal in entity Animal . Note: The Animal entity actually has 4 fields ( name , paragraph , BlobKey , and blobServingUrl as String). But the endpoint api only allows saving

NHibernate narrowing proxy warning

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We are building an ASP.NET MVC application utilizing NH for data access. Using NH Profiler I see a lot of warnings like "WARN: Narrowing proxy to Domain.CaseTask - this operation breaks ==". I get these very often when executing queries for classes which are mapped in a table per subclass, for example, using the NH Linq provider: Query<ICaseTask>().Where(c => c.Assignee == Of || c.Operator == Of) where the class CaseTask inherits from Task, triggers the warning. Information about the warning in the internet is scarce and mostly hints that