[Reflect] object-oriented C ++

Object:

Is a self-contained entity, with a set of properties and behavior can be identified is identified.

Simply put, all things are all objects . Some see see inside, tangible, audible all objects.

class:

Abstract class is a collection of objects with the same properties and functions.

The property is the function of these objects extracted from general to specific concepts.

Example:

The real object.

This particular abstract set by the class object is formed. From the particular to the general concept.

Package:

Each object contains all the information it needed to operate.

advantage:

  1. Good encapsulation can be reduced coupling
  2. The class can be modified to achieve internal freedom
  3. Class has a clear external interface

inherit:

Relationship "is-a", B is A, the cat is an animal.

It is the successor of the successor of specialization, because there is the successor to the characteristics successor, but also has its own personality.

Inherited three characteristics:

  1. Subclass has no private properties and functions of the parent class.
  2. Subclass can extend the properties and functions of the parent class does not have.
  3. Subclass can implement the parent class in their own way were able to (rewrite)

Advantages: Inheritance that a common portion of all subclasses of the parent class in such code-sharing.

Disadvantages: change the parent class, subclass must not change. Inheritance will destroy the package, details of the parent class implements exposed to subclass.

Polymorphic:

Represent different objects can perform the same action, but to be executed by their own implementation code.

note:

  1. Sub-category to appear as the parent class.
  2. Subclass at work in their own ways.
  3. Appeared as a subclass of the parent class, subclass-specific properties and methods are not available.

How it works: When a method is called, regardless of whether the object is converted to its parent, there is only the very end of the object inheritance chain located realize method is invoked. Virtual dynamic binding process is carried out in accordance with its runtime type .

Abstract class:

In C ++ virtual base class is an abstract class, which has a pure virtual function.

note:

  1. An abstract class can not be instantiated.
  2. Abstract method is a method must be overridden by subclasses of.
  3. If the class contains abstract methods, the class must be defined as an abstract class.

Abstract class represents an abstraction in a form of inheritance tree, leaf nodes because there were concrete class, because when a branch node is an abstract class.

interface:

Is the implicit public methods and attributes are combined to encapsulate specific functionality of the collection.

C ++ interface and does not say, but also a special abstract class can be compared to the interface.

Abstract class distinction and C ++ interface :( stand point of understanding)

  1. Abstract class can have non-virtual functions, there must be an interface are pure virtual function.
  2. Abstract class functions do not have to implement class inheritance, but the interface must be fully realized.
  3. Other object-oriented languages, a class can support multiple interfaces, a plurality of classes may also support the same interface.
  4. Abstract object class, an abstract class is a class (whole class) abstraction, the interface is an abstract behavior (parts of the class) is .
  5. If the behavior across objects of different classes, you can use the interface. For some similarity to the class object classes, inheritance abstract class.
    For example: cats, dogs are animals, so the animal can be an abstract class. Aircraft, Superman is completely unrelated classes, but can "fly", so "fly" may be designed to interface.
  6. From a design point of speaking, an abstract class is a subclass found from a public thing, after generalization out of the parent class , then subclass inherits the parent class; and the interface is simply unaware of the existence of a subclass, a method to realize how uncertain , pre-defined .

Reference books: Lying design pattern

Guess you like

Origin www.cnblogs.com/LampsAsarum/p/12153050.html