Software design - Lecture 34. The main topics covered in this chapter include: structural design patterns; adapter or wrapper design pattern; laptop power supply to AC power supply Example; reasons for incompatibility; adapter pattern defined; issues in adapter design pattern;...
Trang 1Lecture : 34
1
Trang 2They deal with how classes and objects deal with to form large structures
Structural Design patterns use inheritance to compose
interfaces or implementations
Structural Design Patterns basically ease the design by
identifying the relationships between entities
Trang 33
Trang 4Pattern
Trang 7 This could happen due to various reasons such as the existing interface may be too detailed, or it
may lack in detail, or the terminology used by the interface may be different from what the client is looking for.
7
Trang 8 Keeping the client code intact we need to write a new class which will make use of services offered
by the class.
Convert the services offered by class to the client
in such a way that functionality will not be changed and the class will become reusable as shown in next slide.
Trang 13“Adapter pattern convert the interface of the class into a form what client expects. Adapter let the classes work together which couldn’t otherwise due to incompatible interfaces.”
13
Trang 14 Due to adapter class the changes are encapsulated within it and client is decoupled from the changes in the class.
Trang 15 We want to use the existing class and its interface does not match with the one you need.
In case of reusable classes due NonCompatible interfaces it is not possible to reuse them.
15
Trang 16Pattern
Trang 18 Client call operations on Adaptor instance, which
in return call adaptee opertions that carry out the request.
Trang 19 Object Adapters (Discussed till now)
Class Adapters
19
Trang 20Class Diagram of Class Adapter
Trang 23break;
case SUNDAY: System.out.println("Weekends are best.");
break; default: System.out.println("Midweek days are soso."); break; } }
23