Principles of design patterns:Programming with excuses
The role of the factory model:
A. In application design, object creation is concentrated in one place or managed by a certain class (spring)
B. You can directly add objects without modifying the application, which is also conducive to object maintenance.
Types of factory models:
A. Simple Factory
B. Factory m
OOA Object-Oriented Analysis
Object-Oriented Analysis generates three analysis models
Function Model (Use Case Model)
Object Model: analyzes the use case model, breaks down the system into collaborative analysis classes, and describes the relationship between properties and objects of objects through class charts/object graphs, is the static model of the system.
Dynamic Model: describes the dynamic behavior of the system. It describes the interacti
() {system. out. println ("Meat folder-dedicated bag-packed");}/*** secret-Baking 2 minutes */public final void fire () {system. out. println ("Meat folder-dedicated device-baking ");}}
Now, we must use our official raw materials as raw materials.
Definition:
1. provide an interface: public interface roujiamoylfactroy
2. Create the related or dependent object family public meat createmeat (); Public yuanliao createyuanliao (); our interface is used to create a series of raw materials.
Now, let
have missed something. On the right side of the graph, we find the current color and size of the item, and allow users to select other colors and sizes. This gives us some questions about what the "color" and "size" Here are. The different colors of a product are different. After thinking, we found that we have confused two concepts: "goods" and "goods ". Goods of different specifications are independent commodities. For example, a trousers with l, m, and a USB flash drive with 16 GB or 32 GB a
logic. Different subclasses can implement these abstract methods in different ways, thus having different implementations of the remaining logic. First, a top-level logical framework is developed, and the details of the logic are left to the specific subclasses to implement11. Visitor Mode (Visitor)The purpose of the visitor pattern is to encapsulate some operations that are applied to a data structure element. Once these operations need to be modified, the data structure that accepts the opera
clearer.Interface Ifactory {public ICar createcar ();} Class Factory implements Ifactory {public ICar Createcar () {Engine engine = new engine (); Underpan Underpan = new Underpan (); Wheel Wheel = new Wheel () ICar car = new Car (Underpan, Wheel, engine); return car;}} public class Client {public static void main (string[] args) {Ifactory factory = new Factory (); ICar car = Factory.createcar (); Car.show ();}}After using the factory method, the coupling degree of the caller is greatly reduced
Introduction
The reason why the name is "0 of design patterns" is that the simple factory model does not belong to one of 23 gof design patterns. It is determined by a factory object to create a product instance. The simple factory model is the simplest and Practical Model in the factory model family. It can be understood as a special implementation of different factory
, nor does it create a singleton object, thus allowing lazy lazy loading. In other words, this approach can guarantee both lazy loading and thread safety.5. EnumerationPublic enum singleton{ instance; public void Whatevermethod () {} }There are common drawbacks to the four ways in which you can implement a single example:1) Additional work is required for serialization, or a new instance is created each time a serialized object is deserialized.2) You can use reflection to forcibly invok
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.