training design patterns facade
DESCRIPTION
Learn design patternsTRANSCRIPT
![Page 1: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/1.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential 1
Balint Eniko
Facade Design
Pattern
URSS Training:
16.10.2007
![Page 2: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/2.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Facade Class Diagram
Example
2
![Page 3: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/3.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Facade Class Diagram
Example
3
![Page 4: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/4.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Definition
▶ Provide a unified interface to a set of interfaces in a subsystem.
▶ Defines a higher-level interface that makes the subsystem easier to use.
4
![Page 5: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/5.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Facade Class Diagram
Example
5
![Page 6: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/6.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Motivation
▶ Structuring a system into subsystems helps reduce complexity
▶ The interface exposed by the classes in a subsystem or set of subsystems can become quite complex
▶ One solution: to introduce a facade object that provides a single, simplified interface
6
![Page 7: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/7.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Facade Class Diagram
Example
7
![Page 8: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/8.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Applicability
▶ Use the Facade pattern:
▷To provide a simple interface to a complex subsystem.
▷This interface is good enough for most clients; more sophisticated clients can look beyond the facade.
▷To decouple the classes of the subsystem from its clients and other subsystems subsystem independence and portability
8
![Page 9: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/9.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Facade Class Diagram
Example
9
![Page 10: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/10.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Benefits and Drawbacks
▶ It hides the implementation of the subsystem from clients, making the subsystem easier to use
▶ It promotes weak coupling between the subsystem and its clients change the classes without affecting the clients
▶ It does not prevent sophisticated clients from accessing the underlying classes!
▶ It does not add any functionality, it just simplifies interfaces!
10
![Page 11: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/11.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Facade Class Diagram
Example
11
![Page 12: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/12.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Facade Class Diagram
12
![Page 13: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/13.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Agenda
Definition
Motivation
Applicability
Benefits and Drawbacks
Façade Class Diagram
Example
13
![Page 14: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/14.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Example
▶ Hiding the parts of a complicated calendar API behind a more user friendly façade.
▶ Classes: UserfriendlyDate.java (pattern)
FacadePattern.java (client)
14
![Page 15: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/15.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Example - UserfriendlyDate
class UserfriendlyDate { Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); public UserfriendlyDate (String isodate_ymd) throws ParseException {
Date date = sdf.parse(isodate_ymd); cal.setTime(date);
} public void addDays (int days) {
cal.add (Calendar. DAY_OF_MONTH, days); } public String toString() {
return sdf.format(cal.getTime());}
}
15
![Page 16: Training Design Patterns Facade](https://reader033.vdocument.in/reader033/viewer/2022051113/563db7be550346aa9a8d8586/html5/thumbnails/16.jpg)
USS- EFCluj- Napoca, 2011
internal / confidential
Example - Client
class FacadePatternClient { public static void main(String[] args) throws ParseException {
UserfriendlyDate d = new UserfriendlyDate("1980-08-20"); System.out.println ("Date: " + d.toString());
d.addDays(20);System.out.println ("20 days after: " + d.toString());
} }
▶ Example output:
Date: 1980-08-20
20 days after: 1980-09-09
16