Object-oriented design with some foundations of implementation but important concepts

xiaoxiao2021-03-06  15

In the object-oriented design and implementation, we must spend time and energy to figure out these concepts: abstraction, packaging, inheritance and polymorphism,

And object-oriented design principles, otherwise it will not really understand the object-oriented soul, and will not feel object-oriented design ideas.

Bring the benefits. After studying for a few years OO and several practice, I am determined to summarize these most basic things. And use these problems as an analysis

Example. 1. Differences between interfaces and classes 2. Why do you give priority to synthetic aggregation 2. Polymorphism will bring us convenience 4. What is the relationship between several design principles? Is it useful? What is it? Caught two rabbits while running? Answer: 1. The interface only describes the characteristics of the method, and does not give an implementation of the method;

Therefore, the interface will be separated by the characteristics and implementation of the method. This segmentation is reflected in the interface often represents a role, it is packaged with the role.

Relevant operations and properties, and the class that implements this interface is an actor who plays this role. A role can be played by different actors.

In addition to playing a common role, different actors do not require any other common situations. In order to make it very clear, we can also make this problem more complex, discuss the relationship between the interface, abstract classes and specific classes.

First, what is abstract? It can be said that it is not an abstraction. As far as my understanding is, I am looking for a bunch of things.

Late. In Java, even if any two unhappy things are abstract, because everything is a object; can be abstract

Object class, in fact Java is doing this. For example: We can abstract the characters of the manager and the students in adults or occupations;

The angles and circular abstractions, etc. Object-oriented has an important principle DIP (dependencies inverted principle) is to say to abstract programming; our

The program is to depend on abstraction rather than specific. For example, we define a method of mankind to set its transport, we should pass abstract

Parameters of the type of transportation. Void setvehicle (vehicle v); this is in the call, due to the support of the polymorphism,

SETVEHICLE (New Car ()); Object-oriented has an important principle OCP (opening and closing principle), our design is open;

Change the closed. How can I do this? It is abstraction, we abstract the logic that is estimated in the future, then for abstraction

Programming, only need to join new logic when expanding, no need to modify existing logic. It is important to know that if there is no abstraction, it is difficult.

make it happen. By abstract us can also greatly increase the reuse of the code. Interfaces and abstractions are implementation methods for Java abstraction. Specific classes can implement interfaces or inheritance abstraction class (also said in design mode

Try not to inherit from specific classes). Why is there an abstract class to interface? This is the case, Java language is a single inheritance language, and a class can only have a super class.

So in many cases, this specific class may already have a super class, this time, it is impossible to add a new super class.

. If you have to do it, you have to add this new superclass to the existing superclars to form an excerptic situation; if this super super superchard

The location of the class has also been occupied, so there is only to continue, only the uppermost end of the level structure that moves to the class. In this case. In one

The specific class of insertion is to become a modification of all classes in the entire level structure. What's more, if the super class is a software provider

What should I do? The interface makes the insertability possible. Any interface can be implemented in any class in a class level structure.

The mouth affects all the subclasses of such classes, and we summarize the differences between interfaces and abstractions: a. Language level, class can implement multiple interfaces, but only one abstract class can be inherited; abstract classes can have specific methods And there is no interface in the interface; the abstract class can implement the interface, but the interface cannot be inherited. B. Design level, if there is a common logic between subcles, it should be designed to be an abstract class; if it is the IS-A relationship

Consider designing an abstract class, just a function, nature, and considering the interface more in line with semantics. For example: Abstract Class Door {Abstract Void Open (); Abstract Void Close ();} interface alarm {void alarm ();} class alarmdoor extends door imports alarm {void open () {... This is a reasonable design of void alarm () {...}}. Abstract class allows the part to implement classes, and the interface does not contain any member's implementation. We can say this: the interface is more than the abstract class

abstract. Comparison of abstract classes and specific classes is as follows: The specific class is not used to inherit, and the abstraction class can only be used inheritance. Abstract classes should have as much as possible and

Try to have less data. The comparison of the interface and the specific class is as follows: A concrete class If an interface is implemented, it must implement all the methods specified in the interface. 2. There are two main types in multiplexes: inheritance multiplexing and synthetic aggregation. However, inheritance reuse is often abused. Experience tells us that the inheritance of the LSP (Riviera) and COAD law

It is unreasonable, which will receive a very absurd result inheritance. There are several important disadvantages. Synthetic aggregates can be avoided: a. Inheritance multiplexing packaging, white box multiplexing, because inheritance Realization details are exposed to the subclass. We know

The installation is an object-oriented very important feature, and we can easily manage our code by packaging. We only care about a class of public

Interface, and ignore specific implementation. This makes it easy for us to pay attention when we face a complex class or get a third-party component.

Power is concentrated in our business approach, not to consider detail. Thereby reducing the complexity of the problem. B. If the achievement of the superclass changes, the implementation of the subclass has to change. C. Inheritance is static multiplexed. It is impossible to change during runtime, so there is no sufficient flexibility. This is difficult to make

"The abstraction is decoupled and implemented so that both can vary independently." 3. The goal of software design should be scalable, flexible, can be insertable. To do this, you must use polymorphism as a control method.

. What is the first thing? Don't confuse the concepts of reset, reset, etc., they are not a matter. At this point in this point

The saying is wrong, the heavy load is not the polymorph of our true sense, the most is the polymorphism on the compiler, the same name is in the following methods

The translation has actually been converted to a different method name. Polymorphism is a mechanism that allows us to program a single Class (rather than independent Class), which gives us more elastic add or remove any specific Classes.

4. Design principles include: OCP (Ket Turnover), LSP (Principles of Riviera), DIP (Dependent Inversion Principle), ISP (Interface Isolation Principle), CARP (Synthesis Aggregation Multiplexing Principle), LOD (Dimit) Rule); OCP is the purpose, DIP is means. The LSP is the cornerstone of inheritance. ISP is one of the means of achieving LOD. CARP is a reuse of the principle.

5. The relationship between design patterns and design principles is like thirty-six and grandson's artists. The former is a concrete experience, these experiences reflect the principle; the latter is a more general abstract, more general guiding principle. Grab the maintenanceability and reuse these two methods of running rabbits are: support maintainability multiplexing (while maintaining the maintenanceability of the system).

---------------- Thinking after learning design mode --------

Reference book "Java and Mode", "C # Primer"

转载请注明原文地址:https://www.9cbs.com/read-45769.html

New Post(0)