Thursday, October 14, 2010

The three basic features of object-oriented [1]



Object-oriented three basic characteristics: encapsulation, inheritance, polymorphism.




Package

Package is best understood. Packaging is one of object-oriented features, objects and classes is the main features of the concept.

Package, which is the objective things packaged as an abstract class, and class can only own data and methods of the class or object to reliable operation, carried out on the credible information hiding.

Inherit

Object-oriented programming (OOP) language, one of the main features is the "inheritance." Inheritance refers to a capability: it can use all the features of the existing class, and without the need to re-write the original class of cases, to extend these capabilities.

Create a new class through inheritance known as "subclass" or "derived class."

Inherited class is called "base class", "parent" or "super-class."

The process of succession is from the general to the specific process.

To achieve inheritance, can be "inherited" (Inheritance) and "combination" (Composition) to achieve.

In some OOP languages, a subclass can inherit multiple base classes. However, under normal circumstances, a subclass can only have one base class, to achieve multiple inheritance, can be achieved through a multi-level inheritance.

Way to achieve the concept of succession has three categories: implementation inheritance, interface inheritance and visual inheritance.

1, implementation inheritance is the use of the base class properties and methods without additional coding capacity;

2, the interface is inherited properties and methods using only the name, but the child class must provide the ability to achieve;

3, visual inheritance is the child form (class) using the base form (class) of the appearance and the ability to achieve code.

In considering the use of succession, it is to note that the relationship between the two classes should be "part" relationship. For example, Employee is a person, Manager is a human being, so these two classes can inherit Person type. But the Leg class can not inherit Person class, his legs are not a person.

Abstract class defined by the subclass only the general properties and methods to create, to create an abstract class, use the keyword Interface rather than Class.

OO development paradigm roughly as follows: division 鈫?object 鈫?abstract class to class organized into hierarchical structures (inheritance and synthetic) 鈫?using class and instance of the design and implementation stages.

Polymorphism

Polymorphism (polymorphisn) is to allow you to set up a parent and one or more child objects of his equal technology, assignment, the parent object can be assigned to it based on the current characteristics of the child object in a different manner . In short, in one sentence: to allow the sub-class type of a pointer assignment to the parent class type pointer.

Multi state, there are two ways to cover, heavy.

Coverage refers to the subclass the parent class to redefine the practice of virtual functions.

Overload, is the same name to allow multiple functions, the function of the parameter list of these different (and perhaps the number of different parameters, parameter types may be different, perhaps the two are different).

In fact, the concept of overload is not a "object-oriented programming", the realization is overloaded: the compiler the function of different parameters according to table name of the function of the same name so modified, then these functions become the same name in different functions ( at least for the compiler is so). For example, there are two with the same name function: function func (p: integer): integer; and function func (p: string): integer;. The compiler did modified the function names may be this: int_func, str_func. For these two functions of the call, the compiler has already determined between is static (Remember: static). That is, their addresses at compile time on the binding of the (early binding), thus, overloading and polymorphism has nothing to do! Real and polymorphism related to a "cover." When the sub-class re-defines the parent class's virtual function, the parent pointer assigned to it under a different sub-class pointer, dynamic (Remember: It is dynamic!) Call is sub-class of the function, this function call in can not be determined during compilation (called sub-class virtual function can not give the address). Therefore, such a function address is bound at runtime (late bonding). Conclusion is: overloading is just a language feature, and multi-state has nothing to do has nothing to do with object-oriented! Quoted a Bruce Eckel's words: "Do not be silly, if it is not late bonding, it is not polymorphism."







相关链接:



MP4 to WMP



Yuan established the value of win-win connection



MKV to WMV



ASF to MPG



Golden Abacus eAM State Assets Bureau Haizhu District, GUANGZHOU presence



Proper way to make money: to be a know How to "lose money," the dealer



Five European giants CEO signed a letter opposed to reform the EU patent law



How I Sold 1,000 Cars, 200 Sets Of Villas



Lean Manufacturing In The Seventh To Avoid Mistakes - Transport Waste



Specialist Games Arcade



News about Graphic CAD



Unstoppable P2P



Trojan horse to steal account with Sister Furong be prudent to see hot pictures



how to Troubleshoot a powerbook g4 hard disk



No comments:

Post a Comment