Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
CSE564 Lecture 17
Javier Gonzalez
PRO
September 17, 2020
Programming
0
910
CSE564 Lecture 17
Software Design
Design Patterns
(202110)
Javier Gonzalez
PRO
September 17, 2020
Tweet
Share
More Decks by Javier Gonzalez
See All by Javier Gonzalez
CSE360 Tutorial 01
javiergs
PRO
0
9
JGS594 Lecture 23
javiergs
PRO
0
400
JGS594 Lecture 22
javiergs
PRO
0
380
JGS594 Lecture 21
javiergs
PRO
0
300
JGS594 Lecture 20
javiergs
PRO
0
190
JGS594 Lecture 19
javiergs
PRO
0
340
JGS594 Lecture 18
javiergs
PRO
0
340
JGS594 Lecture 17
javiergs
PRO
0
320
JGS594 Lecture 16
javiergs
PRO
1
520
Other Decks in Programming
See All in Programming
GraphQL+KMM開発でわかったこと / What we learned from GraphQL+KMM development
kubode
0
140
書籍『良いコード/悪いコードで学ぶ設計入門』でエンジニアリングの当たり前を変える
minodriven
3
1.2k
byte列のbit表現を得るencodingライブラリ作った
convto
1
210
Nix for Scala folks
kubukoz
0
140
About Type Syntax Proposal
quramy
1
1.2k
SRE NEXT 2022: Sensible Incident Management for Software Startups
takanabe
2
840
モデリングの費用対効果
masuda220
PRO
4
990
あなたの会社の古いシステム、なんとかしませんか?~システム刷新から考えるDX化への道筋とバリエーション~/webinar20220420-grapecity
grapecity_dev
0
140
モバイルファーストデザインの爆速実装を考える
tanabee8
0
170
既存画面の Jetpack Composeでの書き換え: FAANSでの事例紹介 / Case study of rewriting existing screens with Jetpack Compose
horie1024
0
360
Loom is Blooming
josepaumard
3
570
Named Document って何?
harunakano
0
610
Featured
See All Featured
Statistics for Hackers
jakevdp
781
210k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
11
4.6k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
181
15k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
119
28k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
315
19k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
151
12k
What's new in Ruby 2.0
geeforr
336
30k
Documentation Writing (for coders)
carmenhchung
48
2.5k
Code Review Best Practice
trishagee
41
6.8k
Raft: Consensus for Rubyists
vanstee
126
5.4k
jQuery: Nuts, Bolts and Bling
dougneiner
56
6.4k
Atom: Resistance is Futile
akmur
255
20k
Transcript
jgs CSE 564 Software Design Lecture 17: More Patterns Dr.
Javier Gonzalez-Sanchez javiergs@asu.edu 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 ConcreteHandler1(); Handler h2 = new ConcreteHandler2(); Handler h3 = new ConcreteHandler3(); 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 { protected Handler
successor; public void setSuccessor(Handler successor) { this.successor = successor; } public abstract void HandleRequest(int request); }
jgs 564 00010001 ConcreteHandler class ConcreteHandler1 extends Handler { public
override void HandleRequest(int request) { if (request >= 0 && request < 10) { // code here… } else if (successor != null) { successor.HandleRequest(request); } } } class ConcreteHandler2 extends Handler { 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. javiergs@asu.edu 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.