View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sp01 Final Exam Review: Design Patterns

See Final Exam Review - Sp2001

Comments? Answers? Criticisms?

a. Factory Method and Abstract Factory design patterns are quite similar. How are they similar and how are they different?

Both of these patterns provide an interface where the subclasses
don't know what type of object they want to create. Instead they use
the factory which creates it for them. These are both creational
design patterns because they provide an easy way for the user to make
objects without having to worry about any details on why and how the
object is to be made.
They are different in that the Factory Method design produces a
specific object and the Abstract Factory Method produces a family of
objects which have to be casted down to the specific one you want.
The Factory Method does more work for you and gives you exactly what
you need, while the Abstract Factory gives you a general object and
you have to decide what type of that object you want. In other words,
the Abstract Factory gives you more flexibility, but more work, and
the Factory Method, less felixibility and less work. Two common
tradeoffs.

The similarities are right. On the difefrences, though, there doesn't need to be casting involved in either case. So, what is the difference between them? -Lex Spoon


b. How are the Adapter and Bridge patterns similar and different?

Both of these design patterns recognize the difference between the
interface and the implementation of that interface. This is the only
similarity I can find, otherwise they are very different.
The Bridge pattern is a behavioral pattern and it seperates the
interface from the implementation. That is its primary goal. This
allows for the interface and the implementation to change for every
object. This is helpful in enviroments when it is essential to have
many different types of views and many implementations in each. The
slides talked about "windows" in operating systems which is a good
example. The Adapter pattern, however, is a structural pattern and
changes the normal interface of a class (how a class should look when
using the code as a base), to an interface which is suitable for the
user who will use your program. The adapter pattern brings up a good
point that the way you implement your class doesn't necessary make
a good basis for you UI structure. The adapter changes your
implementation for you.

Gary Brown


Basic similarity: Hard-coding the names of classes into your code is a very bad idea from a maintenance standpoint when those classes are often likely to differ based upon the context of the program. Both AbstractFactory and AbstractMethod realize the need keep instance creation of such classes from occuring inline. Thus, both delegate instance creation responsibility to someone else.

AbstractMethod delegates the responsibility to another method (in the same class). If a different class needs to be created, we simply use inheritance to override the default behavior. It keeps the decision between what class to create localized.

AbstractFactory, however, delegates responsibility to a different class whose sole responsibility is to create objects. All the objects the Factory can create are usually in the same family or are dependent upon each other. Again, how to create specific objects is defined by subclasses while how to put those pieces together may take on a general definition defined in the super, abstract class. AbstractFactory allows other classes to pick a Factory that has the Factory methods needed. AbstractFactory classes are also reusable.

Doug Powers


b) bridge and adapter do have some salient similarities i think.
with bridge we are seeing an abstraction of particular implementation. so we are taking away the details of the model and taking away the excess implementation code. not just hiding details, but separating, coexisting. and i see a very similar setup for adapter. Adapter has a target client domain and an source adaptee interface. This is very general, the target could be a computer made from helium. how do I transfer my JukeBox to a helium computer? well I just need to follow an Adapter design pattern? yes, the interface is wrapt up and reused! but what if we had a Bridge pattern for the JukeBox? then we can create an all new JukeBox based on the abstract JukeBox, but exploit a different computational model with the helium computer (in this imaginary world where helium computer model is unique from — silicon). perhaps my example is ridiculous - but the similarity is there, no? I place an emphasis on a cross-link from existing implementation/interface to abstraction/client/target. i hope the differences are clear, but I'll save them in case I'm already off the mark!
Webb

a) Similarities - provides an interface to the user to decide for the user the exact class to instantiate. both are creational design patterns.

Differences - Factory defines an interface for creating an object, but let subclasses decide which class to instantiate, while Abstract Factory provides an interface for creating families of related or dependent objects. In some sense, select a class which has the Factory methods you need. (straight from the lecture notes/extras/dc.ppt). Therefore, this means that the Abstract Factory provides a higher level of abstraction than the Factory method, and also might create more than one object in an instantiation.

b) Similarities - both are used to modify existing interfaces to meet requirements/expections.

Differences - Bridge is Behavioral. Bridge decouples an abstraction from its implementation so the two can vary independently. There's only one implementor in a Bridge design. Adaptor is Structural. Adaptor provides an interface around another interface so as to enable the interface to meet requirements/expectations. Provides the ability to alter classes conveniently.

chok
(don't quote me on the answer, mostly taken from lecture slides, but i can't be sure i'm right)


finding a quarter under the couch is good.
finding a scorpion under the couch isn't.

Thankyou.
baba is good
The main difference between adapter and bridge is when u use the two.
You use Adapter when u want to "adapt"an existing interface and bridge when u are starting new


Thank you



Link to this Page