Design Pattern From Java To Ruby - Presentation Transcript
Design Pattern -- from Java to Ruby
Richard
E kohe
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Why use Design Pattern
For reuse
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Why use Design Pattern
For communication
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Define a Node interface, all of leaf nodes and internal nodes should implements the interface, internal nodes has a list that includes other internal nodes and leaf nodes and it can add sub-nodes. But leaf node can’t have add sub-node method. Multi-level Menus?
Why use Design Pattern
For communication
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Composite Pattern Multi-level Menus?
Difference from java to ruby
Classes are Objects
Messages, not function call
Duck Typing
Mixin
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Singleton Pattern
ensures a class has only one instance, and provides a global point of access to it
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Singleton Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development You are my only wife You are my only husband
Singleton Pattern -- java
Eager loading
Lazy loading
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Singleton Pattern -- ruby
Ruby built-in singleton
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Built-in (Singleton)
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Ruby for Design Pattern
Observer Pattern
defines a one-to-many dependency between objects so that when one object changes state, all of its dependents are notified and updated automatically
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Temperature Detector Subscribe Notify Notify Temprature changed
Observer Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Java built-in observer
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- ruby
Ruby built-in observer
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Built-in (Singleton, Observer )
Mixin
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Ruby for Design Pattern
Iterator Pattern
provides a way to access the elements of an aggregate object sequentially without exposing its underlying representation
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Iterator Pattern www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Count 1 2 3 10
Iterator Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
External Iterator
Iterator Pattern -- java www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
Internal Iterator
Iterator Pattern -- ruby
Internal Iterator .each
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Built-in (Singleton, Observer, Iterator )
Mixin
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Ruby for Design Pattern
returns an instance of one of several possible classes, depending on the data provided to it.
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Simple Factory Pattern
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Simple Factory Pattern
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Simple Factory Pattern -- java
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Simple Factory Pattern -- java
Classes are Objects
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Simple Factory Pattern -- ruby
Built-in (Singleton, Observer, Iterator)
Mixin
Classes are Objects
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Ruby for Design Pattern
encapsulates a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Command Pattern
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Command Pattern Increase temperature command Decrease temperature command
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Command Pattern -- java
Proc
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Command Pattern -- ruby
Built-in (Singleton, Observer, Iterator)
Mixin
Classes are Objects
Proc
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Ruby for Design Pattern
Make use of ruby advantage www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development Other Design Patterns
Principle
DRY – Don't Repeat Yourself
Convention Over Configuration
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Resources
Design Pattern – Elements of Reusable Object-Oriented Software
Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
Head First Design Pattern
Kathy Sierra, Bert Bates
Design Pattern in Ruby
Russ Olsen
www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Q&A happy to discuss and fix my mistakes www.ekohe.com Web Development & Graphic Design China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
0 comments
Post a comment