Object-oriented three basic characteristics and five basic principles

Source: Internet
Author: User
Object-oriented three basic characteristics and five basic principles
(1) Three basic characteristics: encapsulation, inheritance, polymorphism
Encapsulation:Refers to the abstraction of objective things into classes, and each class protects its own data and methods. A class can put its own data and methods only to allow trusted classes or objects to operate and conceal information that is not trusted. C + + class is a packaging means, the use of class to describe the process of objective things is encapsulation, is essentially an abstraction of objective things.
Inheritance:A method that allows an object of a type to obtain properties of another type of object.                You can use all the features of an existing class without having to rewrite the original class for code reuse and support polymorphism. It generally has three forms: implementation inheritance, visual inheritance, interface inheritance implementation inheritance: the ability to instruct the properties and methods of the base class without additional coding; Visual inheritance: the appearance and implementation code of a subform using the parent form; Port inheritance: Interface inheritance uses only properties and methods, implemented later to subclasses;
Polymorphism :It means that the same entity has many forms at the same time, it is mainly embodied in the inheritance system of the class, which is the technique of setting the parent object equal to one or more of its child objects, after which the parent object can operate in a different way depending on the attributes of the child object currently assigned to it.
(2) five major principles
principle of single responsibility (Single-resposibility principle):A class, it's best to do one thing only, one that causes it to change. The principle of single responsibility can be regarded as the extension of low coupling and cohesion well-structured classes in the object-oriented principle, defining responsibility as the cause of change, so as to increase cohesion to reduce the cause of change.
Open Closure principle (open-closed principle):Software entities should be extensible and not modifiable. That is, open to the extension, to the modification closed.
Liskov Substitution principle (liskov-substituion principle):Subclasses must be able to replace their base classes. This idea is embodied in the constraint criterion of inheritance mechanism, only when subclasses can replace the base class, can we guarantee that the system recognizes subclasses in the runtime, which is the basis of guaranteeing inheritance reuse.
dependency Inversion principle (dependecy-inversion principle):Depends on the abstraction. In particular, the high-level module does not depend on the underlying modules, both of which are dependent on abstraction, abstraction is not dependent on the concrete, and the concrete relies on abstraction.
Interface Isolation principle (Interface-segregation principle):Use multiple small specialized interfaces instead of a large total interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.