Design Mode 1 factory mode Factory
In object-oriented programming, the most common method is to generate an object instance with a new operator. The new operator is used to construct an object instance. However, in some cases, directly generating an object using the new operator may cause some problems. For example, the creation of many types of objects requires
Design Mode 1 factory mode Factory
In object-oriented programming, the most common method is to generate an object instance with a new operator. The new operator is used to construct an object instance. However, in some cases, directly generating an object using the new operator may cause some problems. For example, the creation of many types of objects requires
Original article: http://www.cnblogs.com/zhenyulu/articles/36462.html
The factory mode is dedicated to instantiating a large number of classes with common interfaces. The factory mode dynamically determines which class to instantiate without having to know which class to instantiate each time in advance. The factory model has the following forms:
Simple
1. Simple factory Introduction
Background: In our common programming, we often use new to instantiate an object. In this case, this class is completely dependent on this object. In terms of professional terms, it is highly coupled. When the demand changes, we have to modify the source code, making it difficult to maintain the entire system! However, an important principle of object-oriented (OO) (encapsulat
Simple factory mode: Creates a factory class, and the caller Passes parameters to the factory class to determine whether a specific instance is returned.
First, let's look at the class chart. PS: in the days when I was a code Porter, I didn't need to draw pictures or even draw pictures. So I learned to draw pictures from scratch to deepen my understanding.
This article is derived fromCode Big WetCode Big Wet
Please pay attention to this series of continuous updates. 1 Static Factory
Static Factory Introduction:
Static Factory mode can implement the principle of interface encapsulation isolation. Static Factory mode can be used
1. abstract class implementing interfaces-adapter; 2. Proxy company method-more powerful packaging class; 3. Use of interfaces-factory mode, more powerful Factory
1. abstract class implementing interfaces-adapter
That is, the interface and abstract class are used. The key is Window win = new MyWindow ();
The MyWin
Tips"Effective Java, third Edition" an English version has been published, the second edition of this book presumably many people have read, known as one of the four major Java books, but the second edition of 2009 published, to now nearly 8 years, but with Java 6, 7, 8, and even 9 of the release, the Java language has undergone profound changes.In the first time here translated into Chinese version. For everyone to learn to share.
Entry 1. Consi
AbstractProduct ");}}
Abstract class AbstractOilBox{Public AbstractOilBox (){}}
Class BMWFactory: AbstractFactory{Public override maid (){Return new BMWWheel ();}
Public override maid (){Return new BMWOilBox ();}}
Class BMWWheel: AbstractWheel{Public BMWWheel (){Console. WriteLine ("Create a BMWwheel ");}}
Class BMWOilBox: AbstractOilBox{Public BMWOilBox (){Console. WriteLine ("Create a BMWOilBox ");}}
Class BORAWheel: AbstractWheel{Public BORAWheel (){Console. Write ("Create a BORAWheel ");}}
Java design pattern (1) simple factory pattern is not simpleSimple factory Use Cases
There is an abstract product-Car, and there are a variety of specific sub-products, such as BenzCar, BMWCar, and LandRoverCar. The class diagram is as follows:
As a driver, if you want to drive one of them, such as BenzCar, the most direct way is to directly create the BenzCar in
1. Simple Factory1.1 definition of a simple factory(1) provides a function to create an object instance without concern for its specific implementation .①api interface: Define the functional interfaces required by the customer②impl: Implements the implementation class of the API specifically, there may be multiple③simplefatory class:
method mode or simple factory mode, but a combination of simple factory mode and factory method mode.
Reply by referencing mongodan:
The biggest benefit of simple factory is to centralize changes in one place. In addition, the dependencies in lightsimplefactory. Create () can also be eliminated. My approach is:
{
Public
void Show () {cout"Multi Core A"
};
Class Multicoreb: Public multicore
{
Public
void Show () {cout"Multi Core B"
};
Factory
Class Corefactory
{
Public
virtual singlecore* createsinglecore () = 0;
virtual multicore* createmulticore () = 0;
};
Factory A, designed to produce a type a processor
Class Factorya: Publiccorefactory
{
Public
singlecore* Crea
because this implementation class does not provide any methods other than those defined in the list interface. Therefore, exposing this implementation class to the outside will not have any advantages, on the contrary, it will cause unnecessary troubles and cause unnecessary complexity. This also utilizes the advantages of the static factory method: 1) more control over type instantiation 2) the type of th
Analysis on the factory mode of JAVA design mode (1)1 factory model Introduction
Definition of the factory mode: in short, it is used to instantiate an object and replace the new operation.
The factory mode is dedicated to instant
the more refined documents summarized on the Internet, add some of your ideas and chat in the form of a blog to record --
The factory mode is a creation mode, which can be roughly divided into three types: simple factory mode, factory method mode, and abstract factory mode. It sounds like a
(1) simple factory Model(1) simple factory model 1. Why do I learn the design model?
Design pattern is a set of summary of code Design experiences that are repeatedly used, known to most people, classified and catalogued. The design pattern is used to make code reusable, mak
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.