The document discusses design patterns and principles for object-oriented design. It covers the GRASP patterns for assigning responsibilities to objects, including Creator, Information Expert, Low Coupling, High Cohesion, and Controller. It also discusses the three main categories of design patterns from the Gang of Four (GoF): creational patterns like Factory Method, structural patterns like Bridge and Adapter, and behavioral patterns like Strategy and Observer. The document provides examples of applying these patterns and principles to object-oriented analysis and design.
Machine Learning vs Decision Optimization comparisonAlain Chabrier
Data science is an interdisciplinary field about scientific methods, processes, and systems to extract knowledge or insights from data in various forms, either structured or unstructured.
Data science community is made of people coming from different areas, and who do not always understand each others. Everyone is using his own concepts and not always understands how these map when applied to other techniques.
In particular, Machine Learning experts do not always understand how Decision Optimization concepts maps or differs from their own concepts.
Machine Learning has become a must to improve insight, quality and time to market. But it's also been called the 'high interest credit card of technical debt' with challenges in managing both how it's applied and how its results are consumed.
Conference talk at DevRelCon London 2019.
At the heart of scalable and intuitive APIs is great user experience, but the UX of an API is rarely considered. Learn how to integrate UX strategies to create improved API experiences using real life examples and lessons learned from upgrading Shopify’s own API.
KAOS, is a goal-oriented software requirements capturing approach in requirements engineering. It is a specific Goal modeling method; another is i*. It allows for requirements to be calculated from goal diagrams.[1] KAOS stands for Knowledge Acquisition in automated specification or Keep All Objectives Satisfied.
The University of Oregon and the University of Louvain (Belgium) designed the KAOS methodology in 1990 by Axel van Lamsweerde and others. It is now widely taught worldwide at the university level for capturing software requirements.
This course provides a detailed introduction to the Object Oriented techniques identified by Robert Martin as the SOLID principles of software design. Intended for both novice and intermediary developers, each of the five principles are fully defined and explored. Real-world coding examples are provided for each software tenant to help fully expound upon the design techniques. By the end of the session, developers will be able to identify common code smells while applying SOLID programming practices that ensure clean and maintainable code.
Question 1 Some agile and incremental methods- like extreme programmi.pdfPhilzIGHudsonl
Question 1
Some agile and incremental methods, like extreme programming, claim that they don't need
high-level designs.
Group of answer choices
True
False
Question 2
It is impossible, and not practical, to remove all bugs from a reasonably large system.
Group of answer choices
True
False
Question 3
A successful software system will require zero maintenance.
Group of answer choices
True
False
Question 4
Git belongs in which category of version control systems (VCS)?
Group of answer choices
Local VCS
Centralized VCS
Distributed VCS
Locking VCS
Question 5
Git thinks about its data more like a stream of snapshots as opposed to a collection of file
differences (or deltas).
Group of answer choices
True
False
Question 6
If two team members disagree about an estimate, which of the following can help find a
compromise?
Group of answer choices
Wideband Delphi
discussing assumptions
WBS
a Scrum meeting
Question 7
Which planning method is used by eXtreme Programming (XP)?
Group of answer choices
PROBE
COCOMO II
The Planning Game
Wideband Delphi
Question 8
In the Wideband Delphi process, the project manager would make a good moderator.
Group of answer choices
True
False
Question 9
Which of the following are true of Wideband Delphi? (select all that apply)
Group of answer choices
requires the entire team to correct one another
requires the creation of a WBS
requires a daily stand-up meeting
was developed at the Rand Corporation in the 1940s
involves an estimation team with 3 to 7 members
Flag question: Question 10
Question 10
Which of the following should you have before you begin the Wideband Delphi process? (select
all that apply)
Group of answer choices
WBS
Vision document
Scope document
a Scrum meeting
Flag question: Question 11
Question 11
Which of the following relationships is also known as "generalization"?
Group of answer choices
Has-a
Creates
Is-a
Knows about
Flag question: Question 12
Question 12
The domain model is a dynamic model that captures the behavior of the system.
Group of answer choices
True
False
Flag question: Question 13
Question 13
External systems are always modeled as actors.
Group of answer choices
True
False
Flag question: Question 14
Question 14
Matching
Group of answer choices
validation
[ Choose ] Are we doing the things right? Are we doing the right things?
verification
[ Choose ] Are we doing the things right? Are we doing the right things?
Flag question: Question 15
Question 15
Which of the following rules are part of Osborn's method?
Group of answer choices
solicit user stories
focus on quantity
withold criticism
break rules
encourage unusual ideas
combine and improve ideas
Flag question: Question 16
Question 16
Which of the following are parts of a use case?
Group of answer choices
title
main success scenario
extensions
user stories
Flag question: Question 17
Question 17
A domain model is: (check all that apply)
Group of answer choices
a use case
a graphic that shows relationships
a project glossary
a dictionary of term.
UX STRAT Online 2021 Presentation by Adilakshmi Veerubhotla, IBMUX STRAT
These slides are for the following session presented at the UX STRAT Online 2021 Conference:
"Design Tools to Get the Most from AI"
Adilakshmi Veerubhotla
IBM: UX Architect
Machine learning with Big Data power point presentationDavid Raj Kanthi
This is an article made form the articles of IEEE published in the year 2017
The following presentation has the slides for the Title called the
Machine Learning with Big data. that following presentation which has the challenges and approaches of machine learning with big data.
The integration of the Big Data with Machine Learning has so many challenges that Big data has and what is the approach made by the machine learning mechanism for those challenges.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
Thinking of getting a dog? Be aware that breeds like Pit Bulls, Rottweilers, and German Shepherds can be loyal and dangerous. Proper training and socialization are crucial to preventing aggressive behaviors. Ensure safety by understanding their needs and always supervising interactions. Stay safe, and enjoy your furry friends!
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
1. UNIT IV - DESIGN PATTERNS
GRASP: Designing objects with responsibilities - Creator -
Information expert - Low Coupling - High Cohesion - Controller.
Design Patterns: creational: factory method - structural:
Bridge, Adapter - behavioural: Strategy, observer - Applying
GoF design patterns - Mapping design to code.
OBJECT ORIENTED ANALYSIS AND DESIGN
CS8592
2. Design patterns in architecture
A pattern is a recurring solution to a standard problem.
“A pattern describes a problem
which occurs over and over again
in our environment, and then
describes the core of the solution
to that problem, in such a way that
you can use this solution a million
times over, without ever doing it
the same way twice.”
2
3. Patterns in engineering
How do engineers find and use patterns?
Mature engineering disciplines have handbooks
describing successful solutions to known problems
Automobile designers don't design cars from scratch
using the laws of physics
Instead, they reuse standard designs with successful
track records, learning from experience
Should software engineers make use of patterns? Why?
Developing software from scratch is also expensive
Patterns support reuse of software architecture design
3
4. Pattern in OO Design
A pattern is a named description of a problem and
solution that can be applied in new contexts
A pattern advises us on how to apply the solution in
varying circumstances and considers the forces and
trade-offs
4
5. What is a software pattern?
A design pattern is a general reusable and proven solution to a
commonly occurring problem in software design.
“ A pattern is a named problem/solution pair that can be
applied in new contexts, with advice on how to apply it in
novel situations”
5
Software pattern
5
6. GRASP = General Responsibility Assignment Software
Patterns
Describe fundamental principles for assigning
responsibilities to classes and for designing
interactions between classes
GoF: Gang of Four Design Patterns : 23 pattrens
Well known Pattern Families
6
7. GRASP
Name chosen to suggest the importance of grasping
fundamental principles to successfully design object-
oriented software
Describe fundamental principles of
object design and responsibility
Expressed as patterns
7
8. “Identify requirements, create a domain model and define dynamic
behaviour , define messages to meet requirements , add methods to
the software classes …”
Too Simple!
How do we assign responsibilities to classes?
What methods belong where?
GRASP : Designing Objects With Responsibilities
8
9. Design of behavior implies assigning responsibilities to software
classes.
Responsibilities are assigned to classes of objects during object design.
Responsibility is a contract or obligation of a class
What must a class “know”? [knowing responsibility]
What must a class “do”? [doing responsibility]
Responsability Driven Design-RDD
9
10. What must a class “do”? [doing responsibility]
Take action (create an object, do a calculation)
Initiate action in other objects
Control/coordinate actions in other objects
Doing responsibilities are implemented by means of methods
Methods fulfill responsibilities alone or through collaboration with
other objects and methods.
Ex: A Sale is responsible for creating SalesLineItems” (doing)
Doing Responsibility
10
11. : Sale
makePayment(cashTendered)
: Payment
create(cashTendered)
abstract, implies Sale objects have a
responsibility to create Payments
Sale objects are given a responsibility to create Payments.
The responsibility is invoked with a makePayment message.
Responsibilities and methods : create
11
12. What must a class “know”? [knowing responsibility]
Private encapsulated data
Related objects
Things it can derive or calculate
Knowing responsibilities are related to attributes, associations in the
domain model.
Domain model illustrates attributes and associations => inspires the
“knowing” responsibilities.
Ex : a Sale is responsible for knowing its total” (knowing)
Knowing Responsibility
12
14. Responsibilities are implemented by methods
Some methods act alone and do a task
Some collaborate with other objects to fulfill their responsibility.
Example:
Sale class has getTotal() method, the getTotal() collaborates with
SalesLineItem objects to get the subtotal through getSubtotal()
methods.
RDD and Collaboration
14
15. 9 GRASP patterns
• Creator
• Information Expert
• Low Coupling
• High Cohesion
• Controller
• Polymorphism
• Pure Fabrication
• Indirection
• Don’t Talk to Strangers (Protected Variations)
GRASP Patterns
15
16. Problem: Who creates an A object
Solution: Assign class B the responsibility to create an
instance of class A if one of these is true
• B “contains or aggregate ” A
• B “records” A
• B “closely uses” A
• B “ has the Initializing data for ” A
Creator principle
16
17. B “has the Initializing data for ” A that will be passed to A when it is
created.
Often initiation is done using a constructor with parameters.
e.g. a Payment instance, when created
needs to be initialized with the Sale total.
Sale class knows Sale total. Good candidate for creating Payment
is Sale.
If more than one of the above applies, prefer a class B which
aggregates or contains A.
Creator principle
17
21. : Register : Sale
makeLineItem(quantity)
: SalesLineItem
create(quantity)
Sale objects are given a responsibility to create SaleLineItem.
The responsibility is invoked with a makeLineItem message
Creating a SalesLineItem
21
23. Problem : What is a basic principle by which to assign
responsibilities to objects?
Solution (advice ) : Assign a responsibility to the information
expert , that is the class with the information necessary to
fulfill the responsibility.
“Objects do things related to the information they have.”
Information Expert
23
24. Start assigning responsibilities by clearly stating the
responsibility.
• Who should be responsible for knowing the grand
total of a sale?
Applying Expert in POS Application
24
27. Sale
time
...
getTotal()
:Sale
t = getTotal
New method
Add a Sale class to the Design Model.
Express responsibility of knowing the total of a sale with the method named getTotal.
• What information do we need to know to determine the line item subtotal?
Sale knows about neighbours (associations), SaleLineitems who is responsible for
knowing its subtotal
Partial interaction and class diagrams
27
28. Sale
time
...
getTotal()
SalesLineItem
quantity
getSubtotal()
New method
1 *: st = getSubtotal
: Sale
t = getTotal lineItems[ i ] :
SalesLineItem
this notation will imply we
are iterating over all
elements of a collection
• How does the SalesLineItem find out the product price?
SaleLineItem knows about neighbours ( ProductDescription) to get the price.
SalesLineItem is Expert for Subtotal
28
30. 30
Problem:
How to support low dependency, Low change impact, and
increased reuse?
Solution: Assign responsibilities so that coupling remains
low. Use this principle to evaluate alternatives.
Coupling is a measure of how strongly one class is
• connected to,
• has knowledge of, or
• relies upon other classes.
“Low Coupling” Principle
30
31. Coupling between classes is dependency of one class on
another class
Common form of coupling from Class A to Class B are:
Class A has an attribute (data member or instance variable)
that refers to a Class B instance, or Class B itself.
What is a coupling ?
31
32. What class should be responsible for creating a Payment
instance and associating it with the Sale?
Register?
Sale?
Creator pattern suggests Register should create the Payment.
A register records a payment in the real world.
Low Coupling - POS Case Study
32
33. : Register p: Payment
:Sale
makePayment() 1: create()
2: addPayment(p)
Register is coupled to both Sale and Payment.
What if Register creates Payment?
33
34. : Register :Sale
:Payment
makePayment() 1: makePayment()
1.1. create()
Assuming that the Sale must eventually be coupled to knowledge
of a Payment, having Sale create the Payment does not increase
coupling.
What if Sale creates Payment ?
34
35. A class with low cohesion does too much unrelated work and are:
• Hard to comprehend
• Hard to reuse
• Hard to maintain
• Delicate and constantly affected by change
Cohesion is a measure of how strongly related the responsibilities of an
element (classes, subsystems).
High Cohesion
35
36. Problem
How to keep complexity manageable?
Solution
Assign a responsibility so that cohesion remains high
High Cohesion
36
37. : Register : Sale
addPayment( p )
p : Payment
create()
makePayment()
Low cohesion:
Register is taking part of the responsibility for fulfilling “makePayment” operation and
many other unrelated responsibility ( 50 system operations all received by Register) then
it will become burden with tasks and become incohesive.
Reduced cohesion of Register(creator pattern)
37
38. : Register : Sale
makePayment()
: Payment
create()
makePayment()
Solution:
Delegate the payment creation responsibility to “Sale” to support high cohesion
Higher Cohesion and Lower Coupling
38
39. UI layer does not contain any business logic
Problem:
How to connect UI layer to the business logic layer?
Solution:
If a program receive events from external sources other than its
graphical interface, add an event class to decouple the event
source(s) from the objects that actually handle the events.
Controller Pattern
39
40. What first object beyond the UI layer receives and
coordinates (“controls”) a system operation
message?
Solution: Assign the responsibility to a class that
represents one of the following options:
Controller Pattern
40
41. 1. Represents the overall system or a root object.
e.g., an object called System or Register
Suitable when there are not too many system events
or when UI cannot choose between multiple controllers.
2. A controller for each use case
e.g. processSaleHandler
Options for Control Responsibility
41
42. :R egister
enterItem (id , qua ntity)
:P ro cessS aleH andler
enterItem (id , qua ntity)
Register (POS Terminal) is a specialized device with
software running on it.
ProcessSaleHandler represents a receiver of all system
events of a use case scenario.
Controllers
Controller choices ?
42
43. Which class of object should be responsible for receiving this
system event message?
It is sometimes called the controller or coordinator. It does not
normally do the work, but delegates it to other objects.
The controller is a kind of "facade" onto the domain layer from
the interface layer.
actionPerformed( actionEvent )
: ???
: Cashier
:SaleJFrame
presses button
enterItem(itemID, qty)
UI Layer
Domain
Layer
system operation message
What should be Controller for enterItem?
43
44. C a sh ie r
:S a le JF ra m e
a ctio n P e rfo rm e d ( a ctio n E ve n t )
:S a le
1 : m a ke L in e Ite m (ite m ID , q ty)
U I L a y e r
D o m a in L a y e r
It is u n d e sira b le fo r an in te rfa ce
la ye r o b je ct su ch a s a w in d o w to g e t
in vo lve d in d e cid in g h o w to ha n d le
d o m ain p ro ce sse s .
B u sine ss lo g ic is e m b e d d e d in th e
p re sen ta tio n la ye r, w h ich is n o t u se fu l.
S a le JF ra m e sh o u ld n o t
se n d th is m e ssa g e .
p re sse s b u tto n
Bad Design
44
45. actionPerformed( actionEvent )
:Register
: Cashier
:SaleJFrame
presses button
1: enterItem(itemID, qty)
:Sale
1.1: makeLineItem(itemID, qty)
UI Layer
Domain Layer
system operation message
controller
Controller should delegate the work that needs to be done to other objects.
Good Design
45
46. Design patterns
A pattern is a recurring solution to a standard problem, in a context.
Christopher Alexander, a professor of architecture…
Why would what a prof of architecture says be relevant to software?
“A pattern describes a problem which occurs over and over again in our environment, and
then describes the core of the solution to that problem, in such a way that you can use this
solution a million times over, without ever doing it the same way twice.”
Jim Coplein, a software engineer:
What are dress patterns?
“I could tell you how to make a dress by specifying the route of a scissors through a piece
of cloth in terms of angles and lengths of cut. Or, I could give you a pattern. Reading the
specification, you would have no idea what was being built or if you had built the right thing
when you were finished. The pattern foreshadows the product: it is the rule for making the
thing, butitis also, in many respects, the thing itself.”
46
47. Uses of Design Patterns
Finding appropriate objects.
Determining object granularity.
Specifying object interfaces.
Specifying object implementations.
Programming to an interface not to an
implementation.
47
48. The “gang of four” (GoF)
Erich Gamma
Richard Helm
Ralph Johnson
John Vlissides
Design Patterns - 23 different patterns as solutions to different
classes of problems, in C++ & Smalltalk
48
49. Elements of Design Patterns
Design patterns have 4 essential elements:
Pattern name: increases vocabulary of designers
Problem: intent, context, when to apply
Solution: UML-like structure, abstract code
Consequences: results and tradeoffs
49
50. Three Types of Patterns
Creational patterns:
Deal with initializing and configuring classes and objects
Structural patterns:
Deal with decoupling interface and implementation of classes and
objects
Composition of classes or objects
Behavioral patterns:
Deal with dynamic interactions among societies of classes and
objects
How they distribute responsibility
50
51. Creational Patterns
Abstract Factory:
Factory for building related objects
Builder:
Factory for building complex objects incrementally
Factory Method:
Method in a derived class creates associates
Prototype:
Factory for cloning new instances from a prototype
Singleton:
Factory for a singular (sole) instance
51
52. Structural Patterns
Adapter:
Translator adapts a server interface for a client
Bridge:
Abstraction for binding one of many implementations
Composite:
Structure for building recursive aggregations
Decorator:
Decorator extends an object transparently
Facade:
Simplifies the interface for a subsystem
Flyweight:
Many fine-grained objects shared efficiently.
Proxy:
One object approximates another
52
53. Behavioral Patterns
Observer:
Dependents update automatically when subject changes
State:
Object whose behavior depends on its state
Strategy:
Abstraction for selecting one of many algorithms
Template Method:
Algorithm with some steps supplied by a derived class
Visitor:
Operations applied to elements of a heterogeneous object structure
53
54. Behavioral Patterns (cont.)
Chain of Responsibility:
Request delegated to the responsible service provider
Command:
Request or Action is first-class object, hence re-storable
Iterator:
Aggregate and access elements sequentially
Interpreter:
Language interpreter for a small grammar
Mediator:
Coordinates interactions between its associates
Memento:
Snapshot captures and restores object states privately
54
56. What are creational patterns?
Design patterns that deal with object creation
mechanisms, trying to create objects in a manner suitable to
the situation
Make a system independent of the way in which objects are
created, composed and represented
Recurring themes:
Encapsulate knowledge about which concrete classes the
system uses (so we can change them easily later)
Hide how instances of these classes are created and put
together (so we can change it easily later)
56
57. Benefits of creational patterns
Creational patterns let you program to an interface defined by
an abstract class
That lets you configure a system with “product” objects that
vary widely in structure and functionality
Example: GUI systems
InterViews GUI class library
Multiple look-and-feels
Abstract Factories for different screen components
57
58. Benefits of creational patterns
Generic instantiation – Objects are instantiated without having to
identify a specific class type in client code (Abstract Factory, Factory)
Simplicity – Make instantiation easier: callers do not have to write long
complex code to instantiate and set up an object (Builder, Prototype
pattern)
Creation constraints – Creational patterns can put bounds on who
can create objects, how they are created, and when they are created
58
59. FACTORY METHOD (Class Creational)
Factory Method is to creating objects as Template Method
is to implementing an algorithm.
Factory Method makes a design more customizable and
only a little more complicated.
Factory Methods are routinely specified by an architectural
framework, and then implemented by the user of the
framework.
59
61. Definition
Product defines the interface for objects the factory
method creates.
ConcreteProduct implements the Product interface.
Creator(also refered as Factory because it creates the
Product objects) declares the method FactoryMethod,
which returns a Product object. May call the generating
method for creating Product objects
ConcreteCreator overrides the generating method for
creating ConcreteProduct objects.
61
65. Factory Example
class 350Z implements Car; // fast car
class Ram implements Car; // truck
class Accord implements Car; // family car
Car fast = new 350Z(); // returns fast car
public class carFactory {
public static Car create(String type) {
if (type.equals("fast")) return new 350Z();
if (type.equals("truck")) return new Ram();
else if (type.equals(“family”) return new Accord();
}
}
Car fast = carFactory.create(“fast”); // returns fast car
Product
Factory Method
65
66. Structural Patterns
Adapter:
Translator adapts a server interface for a client
Bridge:
Abstraction for binding one of many implementations
Composite:
Structure for building recursive aggregations
Decorator:
Decorator extends an object transparently
Facade:
Simplifies the interface for a subsystem
Flyweight:
Many fine-grained objects shared efficiently.
Proxy:
One object approximates another
66
67. Context/problem
How to resolve incompatible interfaces or provide a
stable interface to similar components with different
interfaces?
Solution
Convert the original interface of a component into
another interface through an intermediate adapter
object.
Adapter
67
68. Adapter or Intermediary
Adapter is about creating an intermediary abstraction that
translates, or maps, the old component to the new system.
68
69. Adapters use interfaces and polymorphism to add a level
of indirections to varying APIs in other components.
Client
AbstractClass
clientNameForRequiredMethod()
Adapter
clientNameForRequiredMethod()
{ adaptee. requiredMethod();}
adaptee
RequiredClass
requiredMethod()
The Adapter Pattern
69
70. Target - defines the domain-specific interface that Client uses.
Adapter - adapts the interface Adaptee to the Target interface.
Adaptee - defines an existing interface that needs adapting.
Client - collaborates with objects conforming to the Target interface.
Adapter Example
70
74. Adapter functions as a wrapper or modifier of an existing
class. It provides a different or translated view of that class.
Wrapper Class:
74
75. Wrapper Class:
A wrapper class wraps (encloses) around a data type and gives it an object
appearance. 75
76. Bridge
● The bridge pattern is a design pattern used in software
engineering which is meant to "decouple an abstraction from
its implementation so that the two can vary independently".
● The bridge uses encapsulation, aggregation, and can use
inheritance to separate responsibilities into different classes.
● The bridge pattern is often implemented using the class
adapter pattern.
76
77. Structure of Bridge
Abstraction (abstract class)
defines the abstract interface
maintains the Implementor reference.
RefinedAbstraction (normal class)
extends the interface defined by
• Abstraction
Implementor (interface)
defines the interface for implementation
classes
ConcreteImplementor (normal class)
implements the Implementor interface
77
79. Example:
A household switch controlling lights, ceiling fans, etc. is an example of
the Bridge. The purpose of the switch is to turn a device on or off.
79
80. Behavioral Pattern
Behavioral patterns are concerned with the assignment
of responsibilities between objects, or encapsulating
behavior in an object and delegating requests to it.
1. Strategy
2. Observer
80
81. Strategy:
A Strategy defines a set of algorithms that can be used
interchangeably.
Strategy is like Template Method except in its granularity.
Strategy lets you change the guts of an object.
81
82. Strategy: Structure
Strategy - defines an interface common to all supported algorithms. Context uses this interface
to call the algorithm defined by a ConcreteStrategy.
ConcreteStrategy - each concrete strategy implements an algorithm.
Context
contains a reference to a strategy object.
may define an interface that lets strategy accessing its data.
82
86. Observer Pattern
The Observer defines a one-to-many relationship so that
when one object changes state, the others are notified and
updated automatically.
Encapsulate the core (or common or engine) components
in a Subject abstraction, and the variable (or optional or
user interface) components in an Observer hierarchy.
86
88. Structure Definition:
Observable - interface or abstract class defining the operations for
attaching and de-attaching observers to the client. In the GOF book this
class/interface is known as Subject.
ConcreteObservable - concrete Observable class. It maintain the
state of the object and when a change in the state occurs it notifies the
attached Observers.
Observer - interface or abstract class defining the operations to be
used to notify this object.
ConcreteObserverA, ConcreteObserver2 - concrete Observer
implementations.
88
92. Mapping Designs to Code
• Write source code for:
• Class and interface definitions
• Method definitions
• Work from OOA/D artifacts
• Create class definitions for Domain Class Diagrams (DCDs)
• Create methods from Interaction diagrams
• The interaction diagrams and design class diagrams
created during design provide some of the
necessary input for generating code.
92
93. Creating Class definitions from design class diagrams
• Basic class definitions can be written from the design class
diagrams.
• The following information can be extracted:
• Class name
• Attributes: name, type and access specifier
• Method: name, return type, parameters and their types, and its
access specifier
• Elaborate from associations to add reference attributes
93
94. Reference Attributes
94
An attribute that refers to another complex objects.
• Reference Attributes are suggested by associations and navigability in a class diagram.
• Example: A product specification reference on a Sales Line Item. So here we can use
product spec as a complex reference attribute to sales line item class.
95. Containers and Collections
95
• Where an object must maintain visibility to a group of other objects,
such as a group of Sales Line Items in a Sale, object-oriented languages
often use an intermediate container or collection.
• These will be suggested by a multiplicity value greater than one on a
class diagram.
96. Role Names
96
• Each end of an association is a role. Reference Attributes are often suggested by
role names.
(use role names as the names of reference attributes).
97. Collection classes
SalesLineItem
quantity : Integer
getSubtotal()
1..*
Sale
isComplete : Boolean
time : DateTime
becomeComplete()
makeLineItem()
makePayment()
getTtotal()
public class Sale
{
...
private List lineItems = new ArrayList();
}
A collection class is necessary to
maintain attribute visibility to all the
SalesLineItems.
lineItems
What collection class has been added to the design and why?
97
98. Example
public class SalesLineItem
{
private int quantity;
private ProductDescription description;
public SalesLineItem(ProductDescription desc, int qty) { ... }
public Money getSubtotal() { ... }
}
SalesLineItem
quantity : Integer
getSubtotal() : Money
ProductDescription
description : Text
price : Money
itemID : ItemID
...
1
description
98
99. Why implement from least-coupled to most-coupled?
SalesLineItem
quantity : Integer
getSubtotal()
ProductCatalog
...
getProductDesc(...)
ProductDescription
description : Text
price : Money
itemID : ItemID
...
Store
address : Address
name : Text
addSale(...)
Payment
amount : Money
...
1..*
1..*
Register
...
endSale()
enterItem(...)
makeNewSale()
makePayment(...)
Sale
isComplete : Boolean
time : DateTime
becomeComplete()
makeLineItem(...)
makePayment(...)
getTotal()
...
1
1
1
1
1
1
*
1
2
3
4
5
6
7
99
100. Creating methods from Interaction Diagrams
100
• Interaction Diagrams are used to specify methods.
• They give most of the details for what the method does.
105. PM: Class to Code
• class WorkPackage;
• class Project;
• class Activity;
• class Task;
• class WorkProduct;
• class Resource;
• class Skill;
• class ResourceXSkill;
105
106. PM: Class to Code
class WorkPackage
{ // Details omitted };
class Project : public WorkPackage
{ private: CollectionByVal<Activity> theActivity; };
class Activity : public WorkPackage
{ private: Project *theProject;
CollectionByVal<Task> theTask;
CollectionByRef<WorkProduct> theWorkProduct; };
106
110. PM: Sequence to Main
void main (void)
{ char *Name; char *Descr;
Date StartDate; Project aProject;
// provide project Name, descr, and startdate
aProject.setName (Name);
aProject.setDescr (Descr);
aProject.setStartDate (StartDate);
aProject.save (); }
110
111. References
• Text Book 1 : Craig Larman, Applying UML and Patterns: An Introduction to Object Oriented Analysis and Design
and Iterative Development, Third Edition, Pearson Education, 2005.
• Text Book2 : Ali Bahrami, Object Oriented Systems Development, McGraw Hill International Edition, 1999
• https://sparxsystems.com/resources/tutorials/uml/part1.html
111