Object-oriented 3 elements, 5 principles and 6 viewpoints

Source: Internet
Author: User

object-oriented three elements
Package (encapsulation)
Inheritance (inheritance)
Polymorphic (polymorphism)

Object-oriented Five principles
Single Responsibility principle (SRP)
Open-Close principle (OCP)
Liskov substitution principle (LSP)
dependency Inversion principle (DIP)
Interface Isolation principle (ISP)

object-oriented six viewpoints
multiplexing (reusibility)
extension (Extensibility)
separation (separability)
changes (change)
Simplicity (Simplicity)
consistent (coherance)

============================================================================

Object-oriented five basic principles (note: picked from elsewhere)

============================================================================

In the past, the class in the program has been used to encapsulation, 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:

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 (the simplest, easiest, and most difficult 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!

Detailed notes: http://www.cnblogs.com/seacryfly/archive/2011/12/29/blog1.html

Open Closure principle (OCP)

Open and closed, open to extensions, and closed to changes!

Expansion is to extend the current module, when the actual application of our software changes, the emergence of new requirements, we need to expand the module to 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!

Detailed notes: http://www.cnblogs.com/seacryfly/archive/2011/12/29/blog2.html

Richter Replacement principle (LSP)

Subclasses can replace a parent class and appear anywhere the parent class can appear

This principle is also in the implementation of GOF advocated interface-oriented programming! In this principle, the parent class should be implemented using interfaces or abstract classes whenever possible!

subclasses can replace the parent class's place of use by implementing the parent class Interface! with This principle, our clients are implemented by subclasses when using the parent class interface! This means that we rely on the parent interface, the client declares a parent class interface, through its subclasses to implement this time requires that the subclass must be able to replace the parent class wherever it appears, the advantage is that The new subclass of the parent class interface is extended according to the new requirements without affecting the current client's use!

dependency Inversion principle (DIP)

In traditional structured programming, the topmost modules are usually dependent on the following sub-modules, also known as high-level dependence on the lower levels!

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!

Interface Isolation principle (ISP)

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!



Object-oriented 3 elements, 5 principles and 6 viewpoints

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.