Object-oriented features:Package
The package is best understood. Encapsulation is one of the object-oriented features and is the main feature of object and class concepts.
Encapsulation, which is the encapsulation of objective things into abstract classes, and classes can put their own data and methods only trusted class or object operation, to the untrusted information hiding.
Inherited
One of the main functions of object-oriented programming (OOP) language is "inheritance". Inheritance refers to the ability to use all the functionality of an existing class and to extend these capabilities without rewriting the original class.
New classes created through inheritance are called "subclasses" or "derived classes."
The inherited class is called the base class, the parent class, or the superclass.
The process of inheritance is from the general to the special process.
To implement inheritance, it can be implemented through inheritance (inheritance) and combination (composition).
In some OOP languages, a subclass can inherit multiple base classes. However, in general, a subclass can have only one base class, and to implement multiple inheritance, it can be implemented by multilevel inheritance.
Inheritance concepts are implemented in three categories: implementation inheritance, interface inheritance, and visual inheritance.
Implementation inheritance refers to the ability to use the properties and methods of a base class without additional coding;
Interface inheritance refers to the ability to use only the names of properties and methods, but subclasses must provide the implementation;
Visual inheritance is the ability of a subform (class) to use the appearance of a base form (class) and to implement code.
When considering using inheritance, it is important to note that the relationship between the two classes should be a "belongs" relationship. For example, the Employee is a person and the Manager is a person, so these two classes can inherit the People class. But the Leg class cannot inherit the person class, because the leg is not a human.
Abstract classes define only the generic properties and methods that will be created by the subclass.
OO development paradigm is roughly: dividing objects → abstract classes → organizing classes into hierarchical structures (inheritance and compositing) → Designing and implementing several stages with classes and instances.
Inheritance Example
Class ren (object): def __init__ (Self,name,age,zhiye): self.name=name self.age=age self.zhiye=zhiye def zoulu (SELF,DF): print ("%s hui zou lu qu %s"% (SELF.NAME,DF)) def tiaocao (Self,zhiye): print ("%s gai hang zuo %s "% (Self.name,zhiye)) Self.zhiye=zhiyeclass gui (ren): def __init__ (Self,name,age,chiren): super (gui,self). __init__ (Name,age,chiren) self.name=name self.age=age &nbSp; self.chiren=chiren def chileren (Self,chiren): print (' Gui:%s chi l yi ge ren '%self.name) self.chiren=chirenr1=ren ("Jwh", "a", "it") R1.tiaocao ("Python") G1=gui ("Jiangshi", 100 , "Xiaren") G1.chileren ("Chi le ren") print (R1.name,g1.name)
Python Object-oriented 2