(turn) Object-oriented 5 basic features

Source: Internet
Author: User

in the past, the class in the program has been used to encapsulate the inheritance polymorphism is object-oriented design, but it is not encapsulation, inheritance, polymorphism is only the three main object-oriented features, but in the design of the program is not to say that the structure of the class used (or reflected) these three properties are object-oriented,In fact, the real object-oriented design is to meet the following five principles, Five basic principles of object-oriented
Single Responsibility principle (SRP)
Open Closure principle (OCP)
Richter Replacement principle (LSP)
dependency Inversion principle (DIP)
Interface Isolation principle (ISP)Single Responsibility principle (SRP)• A class should have only one reason for it to change (simplest, easiest to understand and least likely to be a design principle)
Employee Class Examples:
For example, in the staff category, the engineers, sales staff, sales managers are in the staff class, the results will be very confusing, under this assumption, each method in the staff class is to determine what is the case, from the class structure will be very bloated, and the above three types of staff, No matter what kind of change in demand, the staff class will change! This is what we don't want to see!

Open Closure principle (OCP)• Open and closed, open to extensions, and closed to changes! Expansion is to extend the existing modules, when the actual application of our software changes, the emergence of new requirements, we need to expand the module, so that it can meet the new requirements!

Change closure is when we extend the module, do not need to have program code and DLL for the source to modify or recompile the file!

This principle is very helpful to us in designing the class, insisting on this principle must consider the interface encapsulation, the abstract mechanism and the polymorphic technology as far as possible!

Richter replacement principle (LSP) • Subclasses can replace the parent class and appear anywhere the parent class can appear • This principle is also in the implementation of GOF advocate for interface programming!
In this principle, the parent class should be implemented using interfaces or abstract classes whenever possible!

Subclass by implementing the parent class interface, can be used for the parent class place!
With this principle, our clients are implemented by subclasses when using the parent class interface!
This means that we rely on the parent interface, declaring a parent class interface on the client, and using its subclasses to implement the
At this point the subclass must be able to replace any of the parent classes, and the benefit is that the new subclass of the parent class interface is extended to the new requirements without affecting the current client's use!

Dependency inversion principle (DIP) • In traditional structured programming, the top-level modules are usually dependent on the following sub-modules for
Called High-level dependency low!
So the dip principle is to reverse this dependency, so that high-level modules do not rely on low-layer modules, so called the dependency inversion principle!

ISP interface Isolation Principle • This principle means that it is much better to use multiple specialized interfaces than to use a single interface!

I have realized that in my actual programming, in order to reduce the definition of the interface, a lot of similar methods are placed in an interface, and finally found that the maintenance and implementation of the interface is too much effort, and the interface is defined by the operation of the client as a commitment, of course, the less the better, the more concise, the better, Too much commitment brings you a lot of energy and time to maintain!

Excerpt from: http://www.cnblogs.com/yellowapplemylove/archive/2011/05/11/2042903.html

(turn) Object-oriented 5 basic features

Related Article

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.