Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
CSE564 Lecture 17
Search
Javier Gonzalez-Sanchez
PRO
September 17, 2020
Programming
1.9k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CSE564 Lecture 17
Software Design
More Design Patterns
(202110)
Javier Gonzalez-Sanchez
PRO
September 17, 2020
More Decks by Javier Gonzalez-Sanchez
See All by Javier Gonzalez-Sanchez
CSC310 Lecture 04
javiergs
PRO
0
34
CSC510 Lecture 03
javiergs
PRO
0
52
CSC310 Lecture 03
javiergs
PRO
0
44
CSC310 Lecture 02
javiergs
PRO
0
63
CSC310 Lecture 01
javiergs
PRO
1
80
CSC510 Lecture 01
javiergs
PRO
1
61
CSC307 Lecture 21
javiergs
PRO
0
73
CSC307 Lecture 17
javiergs
PRO
0
340
CSC305 Lecture 18
javiergs
PRO
0
380
Other Decks in Programming
See All in Programming
What We Talk About When We Talk About XP
m_seki
2
320
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
110
My Marp Sample
sinoue0108
0
140
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
130
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
130
[DroidKaigi 26] How We Moved from Android Studio to Slack
thisaay
0
190
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
180
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.3k
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
270
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
120
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
260
Featured
See All Featured
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
GitHub's CSS Performance
jonrohan
1033
470k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
300
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
520
Producing Creativity
orderedlist
PRO
348
41k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
550
4 Signs Your Business is Dying
shpigford
187
23k
Writing Fast Ruby
sferik
630
63k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
390
Transcript
jgs CSE 564 Software Design Lecture 17: More Patterns Dr.
Javier Gonzalez-Sanchez
[email protected]
javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
jgs 564 00010001 GoF Patterns
jgs Factory Wrapper of a constructor One entire object to
be built in a single method call
jgs 564 00010001 Abstract Factory
jgs 564 00010001 Products public interface Shape { void draw();
} public class RoundedRectangle implements Shape { public void draw() { System.out.println("Inside RoundedRectangle/draw() method."); } } public class RoundedSquare implements Shape { public void draw() { System.out.println("Inside RoundedSquare/draw() method."); } } public class Rectangle implements Shape { public void draw() { System.out.println("Inside Rectangle/draw() method."); } }
jgs 564 00010001 Factories public abstract class AbstractFactory { Shape
getShape(String shapeType) ; } public class ShapeFactory extends AbstractFactory { public Shape getShape(String shapeType){ if(shapeType.equalsIgnoreCase("RECTANGLE")){ return new Rectangle(); }else if(shapeType.equalsIgnoreCase("SQUARE")){ return new Square(); } return null; } }
jgs 564 00010001 Factories public class RoundedShapeFactory extends AbstractFactory {
public Shape getShape(String shapeType){ if(shapeType.equalsIgnoreCase("RECTANGLE")){ return new RoundedRectangle(); }else if(shapeType.equalsIgnoreCase("SQUARE")){ return new RoundedSquare(); } return null; } }
jgs 564 00010001 Client public class Client { public static
void main(String[] args) { AbstractFactory shapeFactory = new ShapeFactory(); //get an object of Shape Rectangle Shape shape1 = shapeFactory.getShape("RECTANGLE"); //call draw method of Shape Rectangle shape1.draw(); //get an object of Shape Square Shape shape2 = shapeFactory.getShape("SQUARE"); //call draw method of Shape Square shape2.draw(); ] //get shape factory AbstractFactory shapeFactory1 = new RoundedShapeFactory(); //get an object of Shape Rectangle Shape shape3 = shapeFactory1.getShape("RECTANGLE"); //call draw method of Shape Rectangle shape3.draw(); //get an object of Shape Square Shape shape4 = shapeFactory1.getShape("SQUARE"); //call draw method of Shape Square shape4.draw(); } }
jgs Test Yourselves
jgs 564 00010001 Workspace.java (part 1 / 2)
jgs 564 00010001 User D B A C
jgs 564 00010001 The System D B A C random
jgs Chain of Responsibility Avoid coupling the sender of a
request to its receiver by giving more than one object a chance to handle the request.
jgs 564 00010001 Chain of Responsibility
jgs 564 00010001 Chain of Responsibility // Setup Chain of
Responsibility Handler h1 = new ConcreteHandler2(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler1(); h1.SetSuccessor(h2); h2.SetSuccessor(h3); // Generate and process request int[] requests = { 2, 5, 14, 22, 18, 3, 27, 20 }; foreach (int i=0; i<requests.lenght; i++) { h1.HandleRequest(request[i]); }
jgs 564 00010001 Handler abstract class Handler { public abstract
void HandleRequest(int request); } class ConcreteHandler1 extends Handler { public override void HandleRequest(int request) { if (request >= 0 && request < 10) { // code here… } else if (successor != null) { successor.HandleRequest(request); } } }
jgs 564 00010001 Handler class ConcreteHandler2 extends Handler { protected
Handler successor; public void setSuccessor(Handler successor) { this.successor = successor; } public override void HandleRequest(int request) { if (request >= 10 && request < 20) { // code here } else if (successor != null) { successor.HandleRequest(request); } } }
jgs 564 00010001 Chain of Responsibility vs Composite vs Decorator
jgs Test Yourselves
jgs 564 00010001 The System D B A C D
B A C Clustering TSP -Nearest Neighbor
jgs 564 00010001 Questions
jgs CSE 564 Software Design Javier Gonzalez-Sanchez, Ph.D.
[email protected]
Fall
2021 Copyright. These slides can only be used as study material for the class CSE564 at ASU. They cannot be distributed or used for another purpose.