Programming Design Patterns to an Interface, not anImplementation program point to the interface, not the implementation ...

Original link: http://www.cnblogs.com/james1207/p/3260343.html


Class inheritance is basically just a mechanism for extending an application's functionality by reusing functionality in parent classes. It lets you define a new kind of object rapidly in terms of an old one. It lets you get new implementations almost for free, inheriting most of what you need from existing classes.

Class inheritance merely provides a mechanism by reusing the basis of the parent class functions for extended application functions. It will make it much faster using the old object to quickly define new objects. It is very light so that you almost get new implementations. Inheritance is getting what you want from an existing class in most cases.

However, implementation reuse is only half the story. Inheritance's ability to define families of objects with identical interfaces (usually by inheriting from an abstract class) is also important. Why?Because polymorphism depends on it.

However, achieving reuse is only half the story. It is important with the ability to inherit the same interface as the object of the definition of family. (Usually achieved by inheriting the abstract class) Why? And because it relies polymorphism.

When inheritance is used carefully (some will say properly), all classes derived from an abstract class will share its interface. This implies that a subclass merely adds or overrides operations and does not hide operations of the parent class. All subclasses can then respond tothe requests in the interface of this abstract class, making them all subtypes of the abstract class.

When the inheritance is prudent to use (some places will say the "right"), all derived from the abstract class will share these interfaces. This is purely a subclass or increase coverage calculation, rather than hide operations of the parent class.

There are two benefits to manipulating objects solely in terms of the interface defined by abstract classes:

1. Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that clients expect.

2. Clients remain unaware of the classesthat implement these objects. Clients only know about the abstract class(es)defining the interface.

According to the operation target abstract class defines the interface has two unique benefits

(1) customers are not aware of specific types of objects they use, as long as customers expect the interface to follow the object.

(2) the customer does not realize that the class that implements the object. Customers just know the definition of this interface is an abstract class.

This so greatly reduces implementation dependencies between subsystems that it leads to the following principle of reusable object-oriented design: Program to an interface, not an implementation.

It also achieved a significant reduction in the dependence between subsystems, which led to a bit of object-oriented design principles: point program interface rather than implementation.

Don't declare variables to be instances of particular concrete classes. Instead, commit only to an interface defined by an abstract class. You will find this to be a common theme of the design patterns in this book.

Not declare variables to achieve certain specific classes. Instead, the interface is achieved by the deployment of the abstract class definition. In this book, you will find this is a common theme.

You have to instantiate concrete classes(that is, specify a particular implementation) somewhere in your system,of course, and the creational patterns(Abstract Factory (99), Builder (110),Factory Method (121), Prototype (133),and Singleton (144) let you do just that.By abstracting the process of object creation, these patterns give you differentways to associate  an interface with

its implementation transparently at instantiation. Creational patterns ensure that your system is written in terms of interfaces, not implementations.

In some parts of the system, you have to instantiate concrete classes (these are the particular implementation).

Of course, creating patterns and monomer will let you do this. Abstract objects created by the process, in the example of the process, these patterns will provide you with easy to perceive different ways to contact these interfaces. Creation mode

We will ensure the security of your system interface, not the implementation.

 

Reproduced in: https: //www.cnblogs.com/james1207/p/3260343.html

Guess you like

Origin blog.csdn.net/weixin_30906185/article/details/94986003