Design Patterns Notes | EduRev

: Design Patterns Notes | EduRev

 Page 1


CSE 403
Design Patterns
Page 2


CSE 403
Design Patterns
Outline
Introduction to design patterns
Creational patterns (constructing objects)
Structural patterns (controlling heap layout)
Behavioral patterns (affecting object semantics)
Slide 2
Page 3


CSE 403
Design Patterns
Outline
Introduction to design patterns
Creational patterns (constructing objects)
Structural patterns (controlling heap layout)
Behavioral patterns (affecting object semantics)
Slide 2
What is a design pattern?
• a standard solution to a common programming problem
– a design or implementation structure that achieves a 
particular purpose particular purpose
– a high-level programming idiom 
• a technique for making code more flexible qg
– reduce coupling among program components
• shorthand for describing program design
dii f i – a description of connections among program components
– the shape of a heap snapshot or object model
Slide 3
Page 4


CSE 403
Design Patterns
Outline
Introduction to design patterns
Creational patterns (constructing objects)
Structural patterns (controlling heap layout)
Behavioral patterns (affecting object semantics)
Slide 2
What is a design pattern?
• a standard solution to a common programming problem
– a design or implementation structure that achieves a 
particular purpose particular purpose
– a high-level programming idiom 
• a technique for making code more flexible qg
– reduce coupling among program components
• shorthand for describing program design
dii f i – a description of connections among program components
– the shape of a heap snapshot or object model
Slide 3
Example 1:  Encapsulation (data hiding)
Problem:  Exposed fields can be directly manipulated
Violations of the representation invariant
Dependences prevent changing the implementation Dependences prevent changing the implementation
Solution:  Hide some components
Permit only stylized access to the object yy j
Disadvantages:
Interface may not (efficiently) provide all desired operations
Idi i d f Indirection may reduce performance
Slide 4
Page 5


CSE 403
Design Patterns
Outline
Introduction to design patterns
Creational patterns (constructing objects)
Structural patterns (controlling heap layout)
Behavioral patterns (affecting object semantics)
Slide 2
What is a design pattern?
• a standard solution to a common programming problem
– a design or implementation structure that achieves a 
particular purpose particular purpose
– a high-level programming idiom 
• a technique for making code more flexible qg
– reduce coupling among program components
• shorthand for describing program design
dii f i – a description of connections among program components
– the shape of a heap snapshot or object model
Slide 3
Example 1:  Encapsulation (data hiding)
Problem:  Exposed fields can be directly manipulated
Violations of the representation invariant
Dependences prevent changing the implementation Dependences prevent changing the implementation
Solution:  Hide some components
Permit only stylized access to the object yy j
Disadvantages:
Interface may not (efficiently) provide all desired operations
Idi i d f Indirection may reduce performance
Slide 4
Example 2:  Subclassing (inheritance)
Problem:  Repetition in implementations
Similar abstractions have similar members (fields, methods)
Solution:  Inherit default members from a superclass
Select an implementation via run-time dispatching
Disadvantages: Disadvantages:
Code for a class is spread out, and thus less understandable
Run-time dispatching introduces overhead
Slide 5
Read More
Offer running on EduRev: Apply code STAYHOME200 to get INR 200 off on our premium plan EduRev Infinity!