I'm working on the following problem in which I need to apply the Adapter Design Pattern. The description makes it sound like the Adapter class should adapt the new temperature sensor's Celsius calculation to the Fahrenheit calculation of the other 3 sensors. However, there is no mention of passing temperature to any method. Does the Adapter instead seem to be handling the adaptation of TS1, 2, and 3's args of dat/time vs. TS4's args of year/month/day/hour/min/sec? Any thoughts here would be greatly appreciated. Here's the problem:
A system uses three (3) temperature sensors produced by the same vendor V1 to monitor the condition of a hardware device at a specific time:
– The first sensor is of type TS1.
– The second sensor is of type TS2.
– The third sensor is of type TS3.
TS1, TS2, and TS3 accept as input a date and time (given in Eastern Standard Time or EST) and return a temperature in Fahrenheit. Time is in the 24-hour time keeping system (e.g., 23:59:59). V1 supplies a class to interface with its sensors:
We would like to add a third sensor of type TS4 provided by vendor V2. TS4 accepts as inputs a year, month, day, and time (specified in Pacific Standard Time or PST) and returns a temperature in 1/10 of Celsius. Time is specified in the AM/PM format (12-hour clock). Below is the interface for TS4:
1) Give the UML class diagram for the application using the object adapter pattern.
2) Provide the implementation code of the UML class diagram given in question 1 in the programming language of your choice. The client application should read a date and time from the user and compute the average temperature of the four sensors at that date and time.
It seems to me that what you need is to be able to write something like this:
So what the TS4Adapter.getTemp() method needs to do is to translate its parameters into equivalent values that the TS4.getTS4Temp() method expects. Then it would take the returned value and translate it to Fahrenheit.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck