1 Software Design 2 Structural Design Patterns They























![24 public static void main(String[] args) {// Access values of Enumerator Enum. Test first. 24 public static void main(String[] args) {// Access values of Enumerator Enum. Test first.](https://slidetodoc.com/presentation_image_h2/825a2b15c35e2b301f1f13ced0be67f7/image-24.jpg)



- Slides: 27
1 Software Design
2 Structural Design Patterns ØThey 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.
3 Structural Design Patterns ØDeal with objects delegating responsibilities to other objects. ØThis behavior results in a layered architecture of components with low degree of coupling. ØFacilitate interobject communication when one object is not accessible to the other by normal means or when an object is not usable because of its incompatible interface.
4 Adapter or Wrapper Design Pattern
5 Adapter or Wrapper Design Pattern ØMotivation ØLaptop power supply to AC power supply Example
6 Adapter Design Pattern ØClients of a class access the services offered by the class through its interface. ØSometimes, an existing class may provide the functionality required by a client, but its interface may not be what the client expects.
7 Reasons for Incompatibility Ø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.
8 Goal Ø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.
9
10
11
12
13 Adapter Pattern Defined “Adapter pattern convert the interface of the class into a form what client expects. Adapter let the classes work together which couldn’t otherwise incompatible interfaces. ” due to
14 Issues in Adapter Design Pattern ØDue to adapter class the changes are encapsulated within it and client is decoupled from the changes in the class.
15 Applicability – When to use ØWe want to use the existing class and its interface does not match with the one you need. ØIn case of reusable classes due Non-Compatible interfaces it is not possible to reuse them.
16 Class Diagram of Adapter Design Pattern
17
18 Flow of Application ØClient call operations on Adaptor instance, which in return call adaptee opertions that carry out the request.
19 Type of Adapters ØObject Adapters (Discussed till now) ØClass Adapters
20 Class Diagram of Class Adapter
21 Example ØData Structures in Java i-e Array, Vector ØEnumerators in Java ØEnumerations
22 Enumerators in Java public enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }
23 public class Enum. Test { Day day; // defining Enumerator varaible public Enum. Test(Day day) { this. day = day; } public void tell. It. Like. It. Is() { switch (day) // accessing Enumerator Values { case MONDAY: System. out. println("Mondays are bad. "); break; case FRIDAY: System. out. println("Fridays are better. "); break; case SUNDAY: System. out. println("Weekends are best. "); break; default: System. out. println("Midweek days are soso. "); break; } }
24 public static void main(String[] args) {// Access values of Enumerator Enum. Test first. Day = new Enum. Test(Day. MONDAY); first. Day. tell. It. Like. It. Is(); Enum. Test third. Day = new Enum. Test(Day. WEDNESDAY); third. Day. tell. It. Like. It. Is(); Enum. Test fifth. Day = new Enum. Test(Day. FRIDAY); fifth. Day. tell. It. Like. It. Is(); Enum. Test sixth. Day = new Enum. Test(Day. SATURDAY); sixth. Day. tell. It. Like. It. Is(); Enum. Test seventh. Day = new Enum. Test(Day. SUNDAY); seventh. Day. tell. It. Like. It. Is(); }}
25
26
27