Java Design Pattern -- Abstract factory pattern (Abstract factory)
Abstract Factory mode can provide interfaces to customers so that the client can create product objects in multiple product families without specifying the specifi
The original English version of the Factory mode is: Define an interface for creating a object, but let subclasses decide class to which. Factory method lets a class defer instantiation to subclass. It means defining an interface for creating objects, letting subclasses decide which class to instantiate, and the factory method delays the instantiation of a class
Have seen "Ruby design mode" before, but gradually forgot. Now bought a big talk design pattern, it does not look so boring, by the way the code in Ruby implementation.
Simple Factory mode:
#-*-Encoding:utf-8-*-#运算类 class Operation Attr_accessor:number_a,:number_b de
F Initialize (number_a = nil, Number_b =
Design | example | source code
Using System;
Namespace Design_pattern
{
public class Computer
{
Private RAM RAM;
Private CPU CPU;
Public Computer (RAM ram,cpu CPU)
{
This. Ram =ram;
This. Cpu =cpu;
Console. WriteLine ("A Computer is composed!" +this. Ram + "" +this. CPU);
}
}
Public abstract class RAM
{
Public abstract Computer Composeacomputer (CPU CPU);
}
Public abstract class CPU
{
Public abstract Computer Composeacomputer (Ram RAM);
}
publ
abstractfactorymethod
Factory. CS
Namespace abstractfactorymethod
Programe. CS
Namespace abstractfactorymethod
Advantage: In the abstract factory mode, the client is not responsible for object creation, but the responsibility is handed over to the specific factory class. The client is only responsible for object calling, so as to clarify the responsibili
1. Pattern Intent
Defines an interface for creating objects, letting subclasses decide which class to instantiate. The factory method defers the instantiation of a class to its subclasses.
The factory method model is a further abstraction and generalization of the simple factory model .
Because of the use of polymorph
Overview
Abstract Factory mode is widely used in the creation of some similar objects due to demand changes. We use the multi-version database that we are most familiar with as a project. Depending on the database, there may be SQL Server, Access, oracle, My SQL, and other databases, so that we can use the factory model to encapsulate similar function operations in each database into their respective objec
objects. There are two such roles: BulbCreator and TubeCreator.
Abstract Product role: the super type of the object created in the factory method mode, that is, the common parent class of the Product object or the common interfaces. In, this role is Light.
Specific Product role: this role implements the interface defined by the abstract Product role. A specific product is created in a specific factory, whi
the factory role cannot form a hierarchy based on inheritance. The above description is from: C # design mode (4)-simple factory pattern
Foreground call:
Class program {static void main (string [] ARGs) {try {console. write ("Enter the number A:"); string strnumbera = console. readline (); console. write ("select the
from sub-classes, and the factory role cannot form a hierarchy based on inheritance. The above description is from: C # design mode (4)-simple factory pattern
Foreground call:
Class Program { Static Void Main ( String [] ARGs ){Try {Console. Write (" Enter the number: "); String Strnumbera = console. Readlin
Raise the question-analyze the problem-solve the problem. This is the general idea of writing argumentative papers. This is exactly what we usually write in this article. So learning a theory also follows this idea, the learning design model is no exception. Before learning any mode, you must first understand the background of this mode, that is, problems encountered in the actual coding or modification and maintenance code, and then analyze the probl
Java Design Pattern -------- abstract factory pattern of creation Pattern
This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020
The factory method mode and the ab
Java Design Pattern -------- simple factory pattern of creation Pattern
This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020
The factory mode is the most common m
that is relevant to the specific business logic. Called by the application to create the corresponding specific product object. In Java it is implemented by a specific class.
Abstract product role (Apple Phone abstract class): It is a specific product that inherits the parent class or is an implemented interface. In Java, there are generally abstract classes or interfaces to implement.
Specific product role (Iphonex phone): The object created by the specific
Mercedes-Benz is needed, but I don't care which workshop the car is produced. The difference between factory pattern and abstract factory pattern can be compared by BMW and Mercedes. In factory pattern, the user only needs to pro
The factory method pattern for Java Design patternsEditor:ShanliJava Research Organization2009-02-25 Source: IT168 website text tag: design mode Java "IT168 technical article"First, the factory method (Factory) modeThe meaning of
Java Design Pattern -------- factory method pattern of creation Pattern
This article is my learning notes, welcome to reprint, but please note the Source: http://blog.csdn.net/jesson20121020
One problem with the simple factory mod
program does not need to know (or care) that it obtains the specific types of objects from these internal factory methods because the client program uses only the generic interfaces of those objects. Abstract Factory mode separates the implementation details of a set of objects from their general usage.
A "factory" is where a product (object) is created to sepa
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.