Design Pattern From Java To Ruby - Presentation Transcript
Design Pattern
-- from Java to Ruby
Richard
Ekohe
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
Why use Design Pattern
Define a Node interface, all of leaf nodes and
internal nodes should implements the
interface, internal nodes has a list that
For communication includes other internal nodes and leaf nodes
and it can add and remove sub-nodes. But
leaf node can’t have add sub-node method.
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Why use Design Pattern
Define a Node interface, all of leaf nodes and
internal nodes should implements the
interface, internal nodes has a list that
For communication includes other internal nodes and leaf nodes
and it can add and remove sub-nodes. But
leaf node can’t have add sub-node method.
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Why use Design Pattern
Define a Node interface, all of leaf nodes and
internal nodes should implements the
interface, internal nodes has a list that
For communication includes other internal nodes and leaf nodes
and it can add and remove sub-nodes. But
leaf node can’t have add sub-node method.
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
Why use Design Pattern
For communication
Composite
Pattern
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
Composite
Pattern
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Difference from java to ruby
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Difference from java to ruby
Classes are Objects
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Difference from java to ruby
Classes are Objects
Messages, not function call
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Difference from java to ruby
Classes are Objects
Messages, not function call
Duck Typing
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
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
Singleton Pattern
You are my
only wife
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Singleton Pattern
You are my
You are my
only husband
only wife
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Singleton Pattern -- java
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Singleton Pattern -- java
Eager loading
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
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
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
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
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
Ruby for Design Pattern
Built-in (Singleton)
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
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
Subscribe
Temperature
Detector
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern
Subscribe
Temprature
Temperature
changed
Detector
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern
Notify Notify
Subscribe
Temprature
Temperature
changed
Detector
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Define interface by yourself
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Define interface by yourself
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Define interface by yourself
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Define interface by yourself
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Define interface by yourself
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Observer Pattern -- java
Define interface by yourself
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 -- 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
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
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
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
Ruby for Design Pattern
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
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
Count 1 2 3 10
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Iterator Pattern -- java
Java built-in Iterator and mock Iterator
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
Iterator Pattern -- java
Java built-in Iterator and mock Iterator
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
Iterator Pattern -- java
Java built-in Iterator and mock Iterator
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
Iterator Pattern -- java
Java built-in Iterator and mock Iterator
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Merb - Offshore Web Development
Iterator Pattern -- ruby
Nothing, just .each
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Iterator Pattern -- ruby
Nothing, just .each
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Iterator Pattern -- ruby
Nothing, just .each
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Ruby for Design Pattern
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
Simple Factory 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 -- java
Compare with String, a lot of if/else
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Simple Factory Pattern -- java
Compare with String, a lot of if/else
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Simple Factory Pattern -- java
Compare with String, a lot of if/else
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Simple Factory Pattern -- java
Compare with String, a lot of if/else
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Simple Factory Pattern -- java
Compare with String, a lot of if/else
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Simple Factory Pattern -- java
Compare with String, a lot of if/else
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Simple Factory Pattern -- ruby
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
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
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
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
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
Command 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 -- java
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Command Pattern -- java
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Command Pattern -- java
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Command Pattern -- java
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Command Pattern -- java
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Command Pattern -- ruby
Proc
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Command Pattern -- ruby
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
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
Other Design Patterns
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
Ruby's Principle
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Ruby's Principle
DRY – Don't Repeat Yourself
www.ekohe.com
Web Development & Graphic Design
China Ruby on Rails Development - Rails Consulting - Rails Services - Merb - Offshore Web Development
Ruby's 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