To Lecture Notes

IT 313 -- Mar 2, 2020

Review Exercise

  1. What is a software design pattern?
    Ans: It is is a general, reusable solution to a commonly occurring problem in software design.
  2. What are the Factory and Singleton patterns?
    Ans: Instead of using a constructor, the Factory pattern uses a static method, traditionally called getInstance, that returns an object.
  3. When do you want to use the Factory pattern?
    Ans: The Factory pattern is used in two situations: (a) when the getInstance method might return objects from an inheritance hierarchy of classes, (b) when objects are reused; when an object is needed, the getInstance method first checks if an object is available to reuse.  If not, a new object is created using a private constructor.
  4. Why is the Singleton pattern controversial?
    Ans: Because only one instance of the class is created, every user wanting to use that object is given a reference to it. This makes the object global; global objects are notoriously difficult to test because it is hard to know who is using the object.
  5. What is the difference between lazy and eager instantiation?
    Ans: Lazy instantiation means wait until the object is used to instantiate it; eager instantiation means that the object is created immediately when the software using it starts up.

Observer Pattern

Project 7

State Pattern

Strategy Pattern