|
From: Debajit Adhikary on 27 Jul 2007 13:05 I have a LinkedList class. Lets say I want to implement a Stack and a Queue using a LinkedList public class Stack { LinkedList linkedList; ... } and so on. In such implementations, (in which a class aggregates another, and uses it extensively for its own implementation), in what cases would it be "correct" to call such an outer class (Stack/Queue) an Adapter for the inner class (LinkedList) ?
From: Daniel T. on 27 Jul 2007 14:46 In article <1185555901.298592.94230(a)g4g2000hsf.googlegroups.com>, Debajit Adhikary <debajit1(a)gmail.com> wrote: > I have a LinkedList class. > > Lets say I want to implement a Stack and a Queue using a LinkedList > > public class Stack { > LinkedList linkedList; > ... > } > > and so on. > > In such implementations, (in which a class aggregates another, and > uses it extensively for its own implementation), in what cases would > it be "correct" to call such an outer class (Stack/Queue) an Adapter > for the inner class (LinkedList) ? The name "Adaptor" is generally reserved for situations where the outer and inner class are logically the same. I.E., just the names of the methods are changed and maybe some other minor differences. For example, if you were using the interface from one linked list but the implementation of a different linked list. In your case, the client code (the code that uses the Stack or Queue) would not work properly if given a LinkedList, even if the method names were changed.
From: Debajit Adhikary on 27 Jul 2007 21:31 On Jul 27, 2:46 pm, "Daniel T." <danie...(a)earthlink.net> wrote: > In article <1185555901.298592.94...(a)g4g2000hsf.googlegroups.com>, > Debajit Adhikary <debaj...(a)gmail.com> wrote: > > > I have a LinkedList class. > > > Lets say I want to implement a Stack and a Queue using a LinkedList > > > public class Stack { > > LinkedList linkedList; > > ... > > } > > > and so on. > > > In such implementations, (in which a class aggregates another, and > > uses it extensively for its own implementation), in what cases would > > it be "correct" to call such an outer class (Stack/Queue) an Adapter > > for the inner class (LinkedList) ? > > The name "Adaptor" is generally reserved for situations where the outer > and inner class are logically the same. I.E., just the names of the > methods are changed and maybe some other minor differences. For example, > if you were using the interface from one linked list but the > implementation of a different linked list. > > In your case, the client code (the code that uses the Stack or Queue) > would not work properly if given a LinkedList, even if the method names > were changed. Thanks
|
Pages: 1 Prev: Unique Identifiers In Class Diagram Next: Design by Contract vs Law of Demeter : Preconditions |