SlideShare uma empresa Scribd logo
1 de 29
Design Patterns Don’t reinvent the wheel Hanoi - April, 2009 Duong Trong Tan, (tandt@fpt.edu.vn)
What are design patterns? They  are common ways of structuring programs typically deal with a small number of classes, but can be of any size provide a communication framework in which ideas can be discussed at a high level can specify how objects are created, how they interact, or how they are structured
Why design patterns? Reuse solutions Vocabulary for development Better software
Who? Alexandre Christopher ‘Gang of Four’:  Erich Gamma, Richard Helm, Ralph Johnson, and John M. Vlissides
What? Gang of Four common design patterns Some new J2EE design patterns
How can design patterns  be derived? They do use the Design Principles ,[object Object]
 Favor composition over inheritance
 Encapsulate what varies
 Strive for loosely coupled between objects that interact
 Classes should OPEN for extension and CLOSE for modification
 Depends on abstraction, not concrete classes
  Don't call us, we'll call you
 A class should have only one reason to change,[object Object]
Singleton public static Counter getInstance() {     if(uInstance == null) { this.uInstance = new Counter();        return this.uInstance;     } else {        return this.uInstance;      } } C
The purpose of Singleton Makes sure only one instance of an object exists within an application.  A better solution compared to global variables  Provide global access to the object instance. Example: Counter, Application Menu System, Application objects, Services, Clients Not as easy as you think: What about threading?
Factory Method Defines an interface for creating an object but lets subclasses decide which class to instantiate. Lets classes defer instantiation to subclasses C
Benefits of Factories We can choose what to instantiate at runtime We can code to an interface Don’t have to know exactly what kind of object we’ll get back We centralize code In order to add new types of objects, we only have to modify one place, the factory 12
Builder C Separate the construction of a complex object from its representation so that the same construction process can create different representations.
Façade S Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. (GoF)
The DBFacade Example Common JDBC uses: Open a connection to DB Close a connection Get all tables from DB Executes a SQL statement Retrieve result from a SELECT statement All That I Need
DatabaseFacade Outlook Client uses DatabaseFacade JDBC API Connection ResultSet ResultSetMetadata Statement DatabaseMetadata Driver …
Decorator S BufferedReader in = new BufferedReader(new FileReader(“foo.in"));
Strategy B Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it
Observer B Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. GoF
MVC What does it hire?
Command B “Let’s hide (encapsulate) the way we call (invoke) methods.”
Example: Menus Consider an application menu system. How do we de-couple our menu system from our document class? Composite Pattern! Menu contains many menu items. ConcreteCommand Client invoker We can do a lot of things (actions) with a document.  Each interface might be different! Command Interface Receiver
AllGoFpatterns

Mais conteúdo relacionado

Mais procurados

Ewan developing the agile mindset for organizational agility
Ewan   developing the agile mindset for organizational agilityEwan   developing the agile mindset for organizational agility
Ewan developing the agile mindset for organizational agility
Magneta AI
 
How to design a 'Good' Embedded Software?
How to design a 'Good' Embedded Software?How to design a 'Good' Embedded Software?
How to design a 'Good' Embedded Software?
apurvaprabhakar
 
Effective work pres 2
Effective work pres 2Effective work pres 2
Effective work pres 2
Leedhenke
 

Mais procurados (20)

[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices
[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices
[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices
 
Introduction to agility
Introduction to agilityIntroduction to agility
Introduction to agility
 
Ewan developing the agile mindset for organizational agility
Ewan   developing the agile mindset for organizational agilityEwan   developing the agile mindset for organizational agility
Ewan developing the agile mindset for organizational agility
 
Scrum plus – why scrum is not enough for successful delivery
Scrum plus – why scrum is not enough for successful deliveryScrum plus – why scrum is not enough for successful delivery
Scrum plus – why scrum is not enough for successful delivery
 
How to design a 'Good' Embedded Software?
How to design a 'Good' Embedded Software?How to design a 'Good' Embedded Software?
How to design a 'Good' Embedded Software?
 
Effective work pres 2
Effective work pres 2Effective work pres 2
Effective work pres 2
 
Understanding Complexity of Organizational and System Dynamics
Understanding Complexity of Organizational and System DynamicsUnderstanding Complexity of Organizational and System Dynamics
Understanding Complexity of Organizational and System Dynamics
 
Lean vs scrum
Lean vs scrumLean vs scrum
Lean vs scrum
 
The Heart Of Agile
The Heart Of AgileThe Heart Of Agile
The Heart Of Agile
 
ScrumOps - Scrum + Practical DevOps
ScrumOps - Scrum + Practical DevOpsScrumOps - Scrum + Practical DevOps
ScrumOps - Scrum + Practical DevOps
 
The Scrum Roles presented by the Scrumlies 2009
The Scrum Roles presented by the Scrumlies 2009The Scrum Roles presented by the Scrumlies 2009
The Scrum Roles presented by the Scrumlies 2009
 
토이프로젝트에서 Data Driven으로 프로젝트하기 (루비콘 클랩팀 최종회고)
토이프로젝트에서 Data Driven으로 프로젝트하기 (루비콘 클랩팀 최종회고)토이프로젝트에서 Data Driven으로 프로젝트하기 (루비콘 클랩팀 최종회고)
토이프로젝트에서 Data Driven으로 프로젝트하기 (루비콘 클랩팀 최종회고)
 
Microsoft + Agile (light)
Microsoft + Agile (light)Microsoft + Agile (light)
Microsoft + Agile (light)
 
Microsoft + Agile
Microsoft + AgileMicrosoft + Agile
Microsoft + Agile
 
FOSS and agile software development
FOSS and agile software developmentFOSS and agile software development
FOSS and agile software development
 
Jasmine automated java script unit testing
Jasmine   automated java script unit testingJasmine   automated java script unit testing
Jasmine automated java script unit testing
 
DevOps Adoption: Challenges & Opportunities
DevOps Adoption: Challenges & OpportunitiesDevOps Adoption: Challenges & Opportunities
DevOps Adoption: Challenges & Opportunities
 
Scrum in One Day
Scrum in One DayScrum in One Day
Scrum in One Day
 
From Monolith to Microservices - What Could Go Wrong?
From Monolith to Microservices - What Could Go Wrong?From Monolith to Microservices - What Could Go Wrong?
From Monolith to Microservices - What Could Go Wrong?
 
Remote-first Team Interactions for Business and Technology Teams @ DevOps Not...
Remote-first Team Interactions for Business and Technology Teams @ DevOps Not...Remote-first Team Interactions for Business and Technology Teams @ DevOps Not...
Remote-first Team Interactions for Business and Technology Teams @ DevOps Not...
 

Destaque

Bai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhatBai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhat
Hường La
 
Hdc de thi hsgmtct hoa 2011(phu)
Hdc de thi hsgmtct hoa 2011(phu)Hdc de thi hsgmtct hoa 2011(phu)
Hdc de thi hsgmtct hoa 2011(phu)
Lâm Dung
 
Sóng điện từ
Sóng điện từSóng điện từ
Sóng điện từ
hoangkianh
 
Câu hỏi trắc nghiệm đáp án a
Câu hỏi trắc nghiệm   đáp án aCâu hỏi trắc nghiệm   đáp án a
Câu hỏi trắc nghiệm đáp án a
Trúc Hương
 
Những vấn đề cơ bản về tỷ giá
Những vấn đề cơ bản về tỷ giáNhững vấn đề cơ bản về tỷ giá
Những vấn đề cơ bản về tỷ giá
khanhehe12
 
Biển đẹp
Biển đẹpBiển đẹp
Biển đẹp
ruaoirua
 
Thống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống Kê
Thống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống KêThống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống Kê
Thống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống Kê
Minh Mại
 

Destaque (20)

IO trong Java
IO trong JavaIO trong Java
IO trong Java
 
Diễn biến thi truong tien te lien ngan hang
Diễn biến thi truong tien te lien ngan hangDiễn biến thi truong tien te lien ngan hang
Diễn biến thi truong tien te lien ngan hang
 
May fx500
May fx500May fx500
May fx500
 
Bai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhatBai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhat
 
Tin hoc dai_cuong_9517
Tin hoc dai_cuong_9517Tin hoc dai_cuong_9517
Tin hoc dai_cuong_9517
 
Giaohangtietkiem.vn - Giải pháp giao hàng TMĐT (eCom Services JSC)
Giaohangtietkiem.vn - Giải pháp giao hàng TMĐT (eCom Services JSC)Giaohangtietkiem.vn - Giải pháp giao hàng TMĐT (eCom Services JSC)
Giaohangtietkiem.vn - Giải pháp giao hàng TMĐT (eCom Services JSC)
 
[Luanvandaihoc.com]xây dựng kinh tế thị trường định hướng xhcn ở việt nam
[Luanvandaihoc.com]xây dựng kinh tế thị trường định hướng xhcn ở việt nam[Luanvandaihoc.com]xây dựng kinh tế thị trường định hướng xhcn ở việt nam
[Luanvandaihoc.com]xây dựng kinh tế thị trường định hướng xhcn ở việt nam
 
Hdc de thi hsgmtct hoa 2011(phu)
Hdc de thi hsgmtct hoa 2011(phu)Hdc de thi hsgmtct hoa 2011(phu)
Hdc de thi hsgmtct hoa 2011(phu)
 
Sóng điện từ
Sóng điện từSóng điện từ
Sóng điện từ
 
Đề cương ôn Sử 11a1 - An Nhơn 3
Đề cương ôn Sử 11a1 - An Nhơn 3Đề cương ôn Sử 11a1 - An Nhơn 3
Đề cương ôn Sử 11a1 - An Nhơn 3
 
KỸ NĂNG GIAO TIẾP HÀNH CHÍNH Bg giaotiephanhchinh
KỸ NĂNG GIAO TIẾP HÀNH CHÍNH      Bg giaotiephanhchinhKỸ NĂNG GIAO TIẾP HÀNH CHÍNH      Bg giaotiephanhchinh
KỸ NĂNG GIAO TIẾP HÀNH CHÍNH Bg giaotiephanhchinh
 
Giai phuong trinh bang excell
Giai phuong trinh bang excellGiai phuong trinh bang excell
Giai phuong trinh bang excell
 
plc 300
plc 300plc 300
plc 300
 
Phụ thuộc hàm và các dạng chuẩn - dhcntt
Phụ thuộc hàm và các dạng chuẩn - dhcnttPhụ thuộc hàm và các dạng chuẩn - dhcntt
Phụ thuộc hàm và các dạng chuẩn - dhcntt
 
Câu hỏi trắc nghiệm đáp án a
Câu hỏi trắc nghiệm   đáp án aCâu hỏi trắc nghiệm   đáp án a
Câu hỏi trắc nghiệm đáp án a
 
Suy diễn thống kê và ngôn ngữ R (1): Tính toán xác suất và mô phỏng
Suy diễn thống kê và ngôn ngữ R (1): Tính toán xác suất và mô phỏngSuy diễn thống kê và ngôn ngữ R (1): Tính toán xác suất và mô phỏng
Suy diễn thống kê và ngôn ngữ R (1): Tính toán xác suất và mô phỏng
 
Những vấn đề cơ bản về tỷ giá
Những vấn đề cơ bản về tỷ giáNhững vấn đề cơ bản về tỷ giá
Những vấn đề cơ bản về tỷ giá
 
Biển đẹp
Biển đẹpBiển đẹp
Biển đẹp
 
Cau hoi on tap lschtkt
Cau hoi on tap lschtktCau hoi on tap lschtkt
Cau hoi on tap lschtkt
 
Thống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống Kê
Thống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống KêThống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống Kê
Thống kê tình hình mua vàng-Báo cáo môn Nguyên Lý Thống Kê
 

Semelhante a Design patterns in brief

Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
danhaley45372
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
Jason Townsend, MBA
 

Semelhante a Design patterns in brief (20)

Patterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docxPatterns (contd)Software Development ProcessDesign patte.docx
Patterns (contd)Software Development ProcessDesign patte.docx
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Prophecy Of Design Patterns
Prophecy Of Design PatternsProphecy Of Design Patterns
Prophecy Of Design Patterns
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
Software design principles - jinal desai
Software design principles - jinal desaiSoftware design principles - jinal desai
Software design principles - jinal desai
 
Bartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design PatternsBartlesville Dot Net User Group Design Patterns
Bartlesville Dot Net User Group Design Patterns
 
C# interview
C# interviewC# interview
C# interview
 
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design PatternsNina Grantcharova - Approach to Separation of Concerns via Design Patterns
Nina Grantcharova - Approach to Separation of Concerns via Design Patterns
 
Modern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design PatternsModern JavaScript Applications: Design Patterns
Modern JavaScript Applications: Design Patterns
 
Gang of Four in Java
Gang of Four in Java Gang of Four in Java
Gang of Four in Java
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Advance oops concepts
Advance oops conceptsAdvance oops concepts
Advance oops concepts
 
1. Mini seminar intro
1. Mini seminar intro1. Mini seminar intro
1. Mini seminar intro
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Design pattern
Design patternDesign pattern
Design pattern
 

Mais de DUONG Trong Tan

Mais de DUONG Trong Tan (20)

Trở thành Agile Coach
Trở thành Agile CoachTrở thành Agile Coach
Trở thành Agile Coach
 
Coder nên biết thêm gì ngoài việc lập trình
Coder nên biết thêm gì ngoài việc lập trìnhCoder nên biết thêm gì ngoài việc lập trình
Coder nên biết thêm gì ngoài việc lập trình
 
Luyện cách hỏi
Luyện cách hỏi Luyện cách hỏi
Luyện cách hỏi
 
Building a Learning Organization
Building a Learning OrganizationBuilding a Learning Organization
Building a Learning Organization
 
Giáo dục thông minh (Smart Education)
Giáo dục thông minh (Smart Education)Giáo dục thông minh (Smart Education)
Giáo dục thông minh (Smart Education)
 
A reflection on constructivism and engineering education
A reflection on constructivism and engineering educationA reflection on constructivism and engineering education
A reflection on constructivism and engineering education
 
Học cách học (version 2.0) - Learning How To Learn
Học cách học (version 2.0) - Learning How To LearnHọc cách học (version 2.0) - Learning How To Learn
Học cách học (version 2.0) - Learning How To Learn
 
Người lớn học như thế nào - Nhìn từ tiếp cận kiến tạo
Người lớn học như thế nào - Nhìn từ tiếp cận kiến tạoNgười lớn học như thế nào - Nhìn từ tiếp cận kiến tạo
Người lớn học như thế nào - Nhìn từ tiếp cận kiến tạo
 
Agile có thể giúp chúng ta những gì?
Agile có thể giúp chúng ta những gì?Agile có thể giúp chúng ta những gì?
Agile có thể giúp chúng ta những gì?
 
Học cách học (Learning How To Learn)
Học cách học (Learning How To Learn)Học cách học (Learning How To Learn)
Học cách học (Learning How To Learn)
 
Các nguyên lí giáo dục
Các nguyên lí giáo dụcCác nguyên lí giáo dục
Các nguyên lí giáo dục
 
Vì sao các tổ chức không học hỏi
Vì sao các tổ chức không học hỏiVì sao các tổ chức không học hỏi
Vì sao các tổ chức không học hỏi
 
Học qua dự án (Project-based Learning)
Học qua dự án (Project-based Learning)Học qua dự án (Project-based Learning)
Học qua dự án (Project-based Learning)
 
Scrum - a tool to achieve agility
Scrum - a tool to achieve agilityScrum - a tool to achieve agility
Scrum - a tool to achieve agility
 
Agile mindset
Agile mindsetAgile mindset
Agile mindset
 
Training is not enough - Coaching your agile team
Training is not enough - Coaching your agile teamTraining is not enough - Coaching your agile team
Training is not enough - Coaching your agile team
 
Đường vào agile - 2013
Đường vào agile - 2013Đường vào agile - 2013
Đường vào agile - 2013
 
ScrumDay Vietnam 2012 - Agile adoption - Nhan
ScrumDay Vietnam 2012 - Agile adoption - NhanScrumDay Vietnam 2012 - Agile adoption - Nhan
ScrumDay Vietnam 2012 - Agile adoption - Nhan
 
ScrumDay Vietnam 2012 - Scrum with Team Foundation Server - Quang
ScrumDay Vietnam 2012 - Scrum with Team Foundation Server - QuangScrumDay Vietnam 2012 - Scrum with Team Foundation Server - Quang
ScrumDay Vietnam 2012 - Scrum with Team Foundation Server - Quang
 
ScrumDay Vietnam 2012- Thực hành XP với Coding Dojo - Tu,Doi
ScrumDay Vietnam 2012- Thực hành XP với Coding Dojo - Tu,DoiScrumDay Vietnam 2012- Thực hành XP với Coding Dojo - Tu,Doi
ScrumDay Vietnam 2012- Thực hành XP với Coding Dojo - Tu,Doi
 

Último

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 

Último (20)

Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 

Design patterns in brief

  • 1. Design Patterns Don’t reinvent the wheel Hanoi - April, 2009 Duong Trong Tan, (tandt@fpt.edu.vn)
  • 2. What are design patterns? They are common ways of structuring programs typically deal with a small number of classes, but can be of any size provide a communication framework in which ideas can be discussed at a high level can specify how objects are created, how they interact, or how they are structured
  • 3. Why design patterns? Reuse solutions Vocabulary for development Better software
  • 4. Who? Alexandre Christopher ‘Gang of Four’: Erich Gamma, Richard Helm, Ralph Johnson, and John M. Vlissides
  • 5. What? Gang of Four common design patterns Some new J2EE design patterns
  • 6.
  • 7. Favor composition over inheritance
  • 9. Strive for loosely coupled between objects that interact
  • 10. Classes should OPEN for extension and CLOSE for modification
  • 11. Depends on abstraction, not concrete classes
  • 12. Don't call us, we'll call you
  • 13.
  • 14.
  • 15. Singleton public static Counter getInstance() { if(uInstance == null) { this.uInstance = new Counter(); return this.uInstance; } else { return this.uInstance; } } C
  • 16. The purpose of Singleton Makes sure only one instance of an object exists within an application. A better solution compared to global variables Provide global access to the object instance. Example: Counter, Application Menu System, Application objects, Services, Clients Not as easy as you think: What about threading?
  • 17. Factory Method Defines an interface for creating an object but lets subclasses decide which class to instantiate. Lets classes defer instantiation to subclasses C
  • 18. Benefits of Factories We can choose what to instantiate at runtime We can code to an interface Don’t have to know exactly what kind of object we’ll get back We centralize code In order to add new types of objects, we only have to modify one place, the factory 12
  • 19. Builder C Separate the construction of a complex object from its representation so that the same construction process can create different representations.
  • 20. Façade S Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-level interface that makes the subsystem easier to use. (GoF)
  • 21. The DBFacade Example Common JDBC uses: Open a connection to DB Close a connection Get all tables from DB Executes a SQL statement Retrieve result from a SELECT statement All That I Need
  • 22. DatabaseFacade Outlook Client uses DatabaseFacade JDBC API Connection ResultSet ResultSetMetadata Statement DatabaseMetadata Driver …
  • 23. Decorator S BufferedReader in = new BufferedReader(new FileReader(“foo.in"));
  • 24. Strategy B Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it
  • 25. Observer B Define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. GoF
  • 26. MVC What does it hire?
  • 27. Command B “Let’s hide (encapsulate) the way we call (invoke) methods.”
  • 28. Example: Menus Consider an application menu system. How do we de-couple our menu system from our document class? Composite Pattern! Menu contains many menu items. ConcreteCommand Client invoker We can do a lot of things (actions) with a document. Each interface might be different! Command Interface Receiver
  • 30.
  • 32.
  • 35. Application Service Alur et al.
  • 36. References E. Gamma, R. Helm, R. Johnson, & J. Vlissides. Design Patterns: Elements of Object-Oriented Software. Addison-Wesley, Boston, 1995. D. Alur, J. Crupi and D. Malks, Core J2EE Patterns: Best Practices and Design Strategies, Second Edition, 2003

Notas do Editor

  1. Initial session for Java developers @ fRun project.
  2. MVC = Model + View + ControllerTan: In desktop apps(ie. Swing, WinForm), it may hire: Observer for connecting 3 layers, Command for views, Singleton or Application control (see Java Desktop Application Framework on Java.net), Strategy for models and many others (if needed).