usingSystem;namespaceconsoleapplication7{classProgram {Static voidMain (string[] args) { //I bought an apple phone.Phone phone =NewApplephone (); //I want to film now.Decorator Applephonewithsticker =Newsticker (phone); //Extended Foil BehaviorApplephonewithsticker.print (); Console.WriteLine ("----------------------\ n"); //now I want to have a pendant.Decorator applephonewithaccessories =NewAccessories (phone); //Expand phone pendant behaviorApplephonewithaccessories.print (); Conso
In the book "Java and Patterns" of Dr. Shanhong, this describes the decoration (Decorator) Pattern: Decorative mode is also known as packaging (Wrapper) mode. Adornment mode extends the functionality of the object transparently to the client, and is an alternative to the inheritance relationship.Structure of the decoration modeDecorating mode dynamically attaches more responsibility to an object in a transparent manner to the customer . In other word
Decoration Mode definition: Dynamically add some additional responsibilities to an object. Just add features. Decorative mode is more flexible than generating subclasses//This also introduces a basic principle in object-oriented design, that is, to use object combinations as much as possible, rather than object inheritanceComponent: The interface of the Component object. Ability to dynamically add responsibilities to these objects//concreatecomponet: Detailed component objects. Implements the Co
PDF download: http://www.tracefact.net/document/decorator.pdf
Fantasy RPG (item forging and Decorator mode) Introduction
Item forging is a common feature in various fantasy games. Take the well-known Diablo for example. Assuming that the role has a single-handed sword, the basic attack power may be only 13, but it has three equipment holes. When the sword is embedded with a sapphire, it has an additional frozen effect and adds 2 more attacking powers.
other commands. The command object is only responsible for executing its own tasks or commands, in addition, the command mode can remember the previous operation, so many text editors usually use the command mode for Undo/Redo operations.
Articles you may be interested in:
Example Analysis of Observer Pattern in Ruby programming in Design Pattern
Instance parsing Implementation of observer mode in Ruby
the Combination Mode and Its Application in Ruby Design Mode Programming
The template method in the design mode applies two examples in Ruby.
Example parsing: Use of Strategy Mode in Ruby Design Mode Programming
The example explains how Ruby uses the decorator mode in th
For the following implementation of the Make_averager () function mentioned in the previous "Python closure" essay, we keep the historical values in the list, each of which requires a re-summation of the average value, which takes up more space and is less efficient when the historical values are high.>>> def make_averager (): ... = []... def averager (new_value): ... Series.append (new_value) ... sum (series) ... Returntotal/len (series) ... Ret
, when bar is called # may or may not be able to access and/or change bar's return value# may or may not be able to access and/or change bar's return value endendendend
This may make it easier to write decorator and speed up the operation.
2. Keyword old
Another feature lacking in Ruby 2.0 is to reference the rewrite method:
class Foo Foo def bardef bar 'Hello''Hello' endendend end class Fooclass Foo def
replace it with the specific operation factory, namely the addition factory, the subtraction factory, the multiplication factory and the Division factory.
Articles you may be interested in:
Detailed description of the structure of the Combination Mode and Its Application in Ruby Design Mode Programming
The template method in the design mode applies two examples in Ruby.
Example parsing: Use of Strategy
end def contains s1.20.s2.20.s3.20.n1.20.r1.20.endf1 = Fund. newf1.buyf1. bytes
Benefit: You don't need to know about all kinds of stocks, you just need to buy and sell funds.
Articles you may be interested in:
Detailed description of the structure of the Combination Mode and Its Application in Ruby Design Mode Programming
The template method in the design mode applies two examples in Ruby.
Example par
1. Why Ruby?
Why do many Java developers focus on Ruby? Ruby is a general-purpose scripting language created in Japan 10 years ago. It is a pure object-oriented language. Unlike Java, everything in ruby is an object. Ruby syntax mainly comes from smalltalk, Python and Ada.
that all kinds of clothes are independent and exposed to the outside. They are worn by one piece without order or control.
Code Version 3
#-*-Encoding: UTF-8-*-class Person attr_accessor: name def initialize (name = nil) @ name = name end def show puts "***** dress up # {name} \ n" endendclass Finery
Articles you may be interested in:
Detailed description of the structure of the Combination Mode and Its Application in Ruby Design Mode Programming
Keywords: Ruby on Rails, instantrails, windows, getting started, tutorial
I always wanted to try Ruby on Rails, but I was not familiar with Apache and MySQL, and I was not confident in setting up the rails environment. So I never started. After learning about instantrails, finally, we set up the Ruby on Rails Development Environment on Windows and started learni
Decorator is an advanced Python syntax. The decorator Can process a function, method, or class. Next, this article will introduce you to the basics of python decorator. If you are interested in the knowledge of python decorator, learning decorator is a high-level Python synt
Demonstrate Ruby's six characteristics that are easy to be misunderstood with actual code. The Code demonstrates ruby misunderstanding.
Introduction: if you are a C ++ developer, you need to use Ruby to quickly execute some prototype designs. When you pick up a Ruby reference book (such as Pickaxe) or browse a Ruby web
ArticleDirectory
1. Origin
2. Make the code more elegant.
3. Make the code more elegant.
4. Add Parameters
5. Decorated functions with return values
6. apply multiple decorators
7. Flexible Use
To understand Python's decorator, you must first know that the function is also an object in Python, so you can
Copy a function to a variable
Use a function as a parameter
Returns a function.
In python, func
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.