Fried cold rice Series: design mode decorative model abstract: Original source: http: www. cnblogs. comAlandre sediment tile pulp Carpenter hope to reprint, keep abstract, thank you! A good piano is an art, and a good article is also an art. I. What is the decorative model Abstract Factory Model II. the structural roles and responsibilities of the decorative Mode
nude");} }Below that definition, shoes, hats, watches and other decorations, etc. don't worry first, we should first define a shoe, hat, watch abstract parent class abstractclothes. In fact, the abstract parent class has a constructor, the parameters inside the constructor are abstract humans, and the usage here is ingenious, which is an essential step to achieve the decorative function.Package com.user;/** * Definition Abstract Ornament * @author
Decorative Mode (Decorator) is to dynamically add some additional responsibilities to an object, and in addition, the decoration mode is more flexible than the generation of subclasses.The structure diagram is as follows:Component is to define an object interface that can dynamically add responsibility to these objects. Concretecomponent is to define a specific object, or to add some responsibility to the object. Decorator
();}}}publicstaticvoidmain(String argsp[]) {ConcreteComponent concreteComponent =newConcreteComponent();ConcreteDecoratorA cA =newConcreteDecoratorA();ConcreteDecoratorB cB =newConcreteDecoratorB();cA.setComponent(concreteComponent);cB.setComponent(concreteComponent);System.out.println("after A:");cA.operation();System.out.println("after B");cB.operation();}
It can be seen that the decorative pattern is the use of setcomponent to be decorated
First, decoration (decorator) mode
The decoration (decorator) mode is also named wrapper (wrapper) mode [GOF95]. Decorative mode extends the functionality of objects transparently to the client, and is an alternative to inheritance relationships.
Introduction
The Monkey King has 72 changes, and each of his changes brings him an added skill. When he became a fish, he could swim in the water, and when he became a sparrow, he could fly in the sky. And
1. Decoration mode (decorator) definition: Also known as packaging (wrapper) mode, decorative mode to the client transparent way to extend the function of the object is an inheritance of the relationship of an alternative.
2. Decoration mode dynamically attaches more responsibility to an object in a transparent manner to the client. In other words, the client does not feel the object before and after decoration what is the difference.
3. The
Web interface design and decorative elements of the website design,Usually, web site design is in the contradiction between rules and anti-rules, technology and anti-technology in pursuit of novelty. The rules of Web interface design of Web site are the same as the rules of print design, which exist in different relationships such as information elements, decorative elements and invensys elements.Web page i
Discover the design pattern of learning more and more so that they learn something too little, should touch something more, go out and walk.Decoration Mode concept:Dynamically add some extra responsibilities to an object, and the decorative pattern is more flexible than generating subclasses for added functionality (big talk design mode)The ability to dynamically extend an object without having to change the original class file and use inheritance. It
dynamically adds additional responsibilities to an object. No matter whether a picture or a picture frame can be hung on the wall, but usually have a picture frame, and is actually a picture frame is hanging on the wall. Before hanging on the wall, the painting can be covered with glass and put into a frame, when the painting, glass and picture frames form an object.
Figure 2 Decorative Pattern object diagram using a picture frame as an exampleD
Responsibilities:Dynamically adds new functionality to an object.Decoration mode is a technique used in place of inheritance, and it is not possible to extend the new functionality of an object without the addition of inheritance.It is more flexible to use the object's association relation instead of the inheritance relation, and avoids the rapid expansion of the type system.Implementation Details:Componment Abstract Component Roles
Real objects and
Today we talk about the design pattern of the decorative design pattern, this in my door IO flow has been used, first of all, look at the definition of decorative design patternsDefined:dynamically add some extra functionality to an object, and in terms of new features, the adornment mode is more flexible than the generation of subclasses.summed up the decorative
are becoming progressively more complex. There are many classes that evolve in the process of applying patterns, and you can use appearances to provide a simpler interface for these subsystems.@: You can use the appearance to layer the child system. Each subsystem level has an appearance as an entry point. Allowing them to communicate through their appearance simplifies their dependencies.What is decorative mode?Decoration mode, without modifying the
As the name implies, the decorative mode is to add some new features to an object, and is dynamic, requires decorative objects and objects are decorated to achieve the same interface, decorative objects hold the object of the decoration objects, the diagram is as follows: The source class is a decorated class, and the decorator class is a
I. Introduction
Consider the two functions max (A, B)Different types of A and B have the same processing format:
Return a
Use existing methods to solve the problem:(1) macro replacement # define max (A, B) (a)
Existing problems: Avoid type check
(2) Heavy Load
Problems: Many overloaded versions are required.
(3) Use function templates
Ii. Template
A template is a parameterized polymorphism tool.Parameterization polymorphism refers to param
Decorative design pattern Resolution: Enhancements to a set of classes.Packaging: Write a Class (wrapper class) to wrap the wrapped object.* * Packaging and packaged objects to implement the same interface.Packaging class to hold a wrapped object.In the implementation of the interface, most of the methods are implemented by invoking the wrapped object, and for the method that needs to be modified."To be popular: when you want to make enhancements to e
pass an object as a parameter and then wrap the object --- change the method or add some new behavior --- the decorative design pattern --- Decorator mode ---decorate modelChange a method:1. by inheriting this class, and then overriding the method2. create decorative objects by passing objects, and re-provide the corresponding methods in the decoration classDisadvantages of Inheritance:1. Single Inheritanc
Decorative mode (decorator): Dynamically add some additional responsibilities to an object, and in terms of added functionality, the adornment mode is more flexible than the subclass.Usage: When the system needs new functionality, it is to add new code to the old class, which usually decorates the core duties or main behaviors of the original class, adding new fields to the main class, new methods, new logic, and thus increasing the complexity of the
To give you painter software users to detailed analysis of the production of mosaic decorative painting tutorial.
Tutorial Sharing:
Mosaic (mosaics) is a traditional architectural decoration technique, which has been popular all over the world since the Middle Ages. Especially in some old church murals, doors and windows and roofs. Now the most we use mosaic is on the wall and the floor and use it to make all kinds of patterns as d
1. Concept:(In my opinion, the pattern is like a thought, under the guidance of this thought, the processing and integration of code and Structure!) It's all a routine! )Decorative mode, also known as packaging (Wrapper) mode, is the ability to extend an object transparently to the client, which is an alternative to the inheritance relationship. Transparent to the client means that the interface is not changed.2. Questions :In the OO design and develo
------Dark Horse programmer--21, character stream filereader,filewriter,bufferedwriter,bufferedreader, decorative design mode, LineNumberReader/*Buffer technology for character streams:For some large files, if you read a word characters write a character, read and write operations are too frequent.In order to solve this problem, buffer technology was introduced.Buffer technology is based on the flow (must have a flow first) to enhance the flow of data
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.