Download presentation
Presentation is loading. Please wait.
Published byGodwin Floyd Modified over 9 years ago
1
Design Patterns (II) Lecture Three
2
Solution to Homework Two Used framework Used design patterns: composite and state Question: what are the differences between frameworks and design patterns?
3
Patterns vs Frameworks Patterns –reuse of design –tells you how to do good design –language independent –often covers general domains –addresses small part of a program architecture
4
Patterns vs Frameworks Framework –reuse of design and code –is a design (generic implementation) –language specific –often covers specific domain –addresses overall program architecture
5
Solution to Digital Watch Problem How many states? –State diagram How to change state? –Who should know what? How to implement state-specific behaviour? –Delegate the responsibility to the right party
6
Java Review Properties Reflection Serialization
7
Visitor Pattern Represent an operation to be performed on the elements of an object structure Let you define a new operation without changing the classes of the elements on which it operates
8
Company Example A company has departments and each department has more than one employee What is the total salary?
9
More Functionality How many departments with more than ten people?
10
Class Structure Evolved A company has several divisions, and each division has several companies –two solutions
11
Discussion Applicability –Operations performed on objects in an object structure depend on their concrete classes –Many distinct and unrelated operations to be performed on objects Differences from Composite Pattern
12
Discussion Separate navigation and processing –calling an operation on an element object with the visitor as an argument (double dispatch) –calling an operation on a visitor with an element as an argument
13
Discussion Make adding new operations easy Gather related operations and separate unrelated ones Visiting across class hierarchies Accumulating state
14
Discussion Adding new concrete classes for the object structure could be hard Break encapsulation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.