[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] / [Samples] / patterns
[Index] [Contents] [Source Text] [About] [Notation] [Copyright] [Comment/Contact] [Search ]
Tue Sep 18 15:26:33 PDT 2007

Contents


    Patterns and Principles

      Good Links on Patterns

      A good list, overview and, discussion of patterns can be found at [ wiki?CategoryPattern ] on the WikiWikiWeb.

      Another source of pattern information is [ Patterns.aspx ] but this is biased towards C# and is an advert for $2,000 courses.

      Here is a nice resource [ http://home.earthlink.net/~huston2/dp/ ] and visual [ patterns.html ] provided by Vince Huston. Here is a quiz [ patterns_quiz.html ]

      The Wikipedia [ http://en.wikipedia.org/wiki/ ] also documents many (if not all) patterns [ Category:Software_design_patterns ] here.

      GRASP -- General Responsibility Assignment Software Patterns

      From Craig Larman [ ../cs375/text.html ]

    1. Expert::=allocate a responsibility to a class that has the information.

    2. Creator::=creating an object should be the responsibility of a class that is closely related to the created object. Or else you can use a GoF Factory -- a Pure_Fabrication.

    3. Low_coupling::=Assign a responsibilities so that class depends less on other classes using a "need to know basis". Organize responsibilities so that classes do not depend on each other two much.

    4. High_cohesion::=Design elements to have strongly related and focused responsibilities".

    5. Controller::=Assign the responsibility for handling system event messages to a class representing either the whole system, device, or subsystem, or representing the use case /scenario within which the system event occurs. [ MVC ] (Model-View-Controler).

    6. Polymorphism::=Give the same name to services in different objects when the services are similar or related. Classify objects, using inheritance/generalization, to allow the right version of a service to be executes for the object in question. Example [ Strategy ] in the GOF patterns below.

    7. Pure_Fabrication::=assigning a highly cohesive set of responsibilities to an artificial convenience class that doesn't represent a problem domain concept.

    8. Indirection::=Assign a responsibility to a class that knows where to find an object that can complete the task, Avoid coupling by an intermediate (smart?) object. You can have indirect access to an abstraction without knowing the precise concrete implementation of the abstraction: You can call all your Pets in the same way.... and the Dogs come to you, and the Cats think about it, for example.

    9. PV::=Protected_variation.
    10. Protected_Variation::=Identify points of predicted variation or instability and assign responsibilities to create a stable interface around them.
      1. Parnas: Separate your design decisions into separate modules. See Parnas.
      2. SDM: Separate physical from logical structures in separate processes.
      3. GoF: Template_Method, Facade, Proxy, Adapter,...

      GoF Patterns

    11. GoF::="The Gang of Four".... see book and
    12. The_Gang_of_Four::abbreviation={Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides}, Four OO thinkers who wrote an influential book of design patterns. [Gammaetal94]

      Many GoF combine two or more GRASP patterns. For example State is a Pure_Fabrication that uses Indirection to protect a class from state changes (PV).

    13. Abstract_factory::GoF=Design a common interface for creating families of similarly or related objects. See Factory. [ wiki?AbstractFactoryPattern ]

    14. Adapter::GoF=Introduce a class to convert the interface of one component into another interface. Think plugs and sockets. make one interface for one or more suppliers. Unlike Proxy, an adapter converts different interfaces into one common one. [ wiki?AdapterPattern ] [ PatternAdapter.aspx ]

    15. Command::GoF=Design objects that know how to do (and undo) a family of tasks and pass them to other objects to be used as needed. [ wiki?CommandPattern ]

    16. Composite::GoF=Make complex and simple kinds of an object share behavior. And often the complex objects keep a list of their parts: each of which is a similar kind of object. [ wiki?CompositePattern ] [ PatternComposite.aspx ]

    17. Decorator::GoF=A class can take an object and wrap new functions around it. [ decorator.gif ] [ TestDecorator.java ] [ wiki?DecoratorPattern ]
    18. Wrapper::=Decorator.

    19. Facade::GoF=A class or object provides a single point of entry for services of a subsystem, Hide a complex system of objects behind a single object. Pay no attention to the man behind the curtain. [ wiki?FacadePattern ] [ PatternFacade.aspx ] [ Facade_pattern ]

    20. Factory::=an object/operation/class is designed solely to create other kinds of object. See Abstract_factory and FactoryMethod. A factory is an alternative to a constructor in a class. Because it is a member of a different class (the factory) we can get objects without having to know precisely what class they are instances of. Other patterns need the ability to create concrete implementations of an abstraction -- but without knowing which implementation has been chosen.

    21. Observer::GoF=An object that implements the operations that let it subscribe to learn about other objects. Objects that need to see what an object is doing can join a collection maintained by the observed object. These are subscribers. The observed object publishes the changes to the subscribers using one or more special operations that a listed in an interface that the observers all implement. It is also possible for an object to subscribe other objects as observers. [ Observer.gif ] [ wiki?ObserverPattern ] [ PatternObserver.aspx ]

    22. Proxy::GoF=Design an object that can stand in for other objects and knows which object it is representing and how to simulate it. As a result we can change the real object with out breaking the client. [ proxy.gif ] [ wiki?ProxyPattern ]

    23. Singleton::GoF=To make sure that there is precisely one object in a class and provide access to it. [ wiki?SingletonPattern ] [ PatternSingleton.aspx ]

    24. Strategy::GoF=Place different ways to do something behind a common interface and use indirection via an object to pick the right one. [ Strategy.gif ] [ wiki?StrategyPattern ] [ PatternStrategy.aspx? ]

    25. State::GoF=When an object changes behaviors (responsibilities) with time place the state in a different object and the behaviors is special kinds of that object. Note: in most programming language can not change its class! [ wiki?StatePattern ]

    26. Template_Method::GoF=A method in a class can use abstract operations (hooks) that are defined in a subclass so that the subclass provides some functionality while using the overall method. The classic example is a method that sorts a vector of data in a Sortable class but uses an undefined "less_than" operation. Other classes extend the Sortable and define "less_than" and can then sort the data Their way, right away. [ wiki?TemplateMethodPattern ] This result is also called a Framework.

      XP Principles

    27. DRY::=Don't repeat yourself.
    28. YAGNI::=You Aint' Gonna Need It. When in doubt leave it out! Keep It Simple, Stupid!

      Persistence Principles

    29. tables::=All data can be expressed by a collection of simple tables.

    30. Persistence_as_a_superclass::=`Put all the persistence code into a superclass and then any class can become persistent by inheriting from the persistence class`. Notice that this can get clumsy and in Java foul up more important extensions.

    31. ACID::principle="Atomic, Consistent, Isolated, and Durable". Jim Gray's ACID principles of Data Base transactions.
      • atomic::=a transaction either completes or does nothing. -- no interupts.
      • consistent::=a transaction never leaves the data in a state that breaks the rules. A marriage has two people: no more, no less.
      • isolated::=The effect of a transaction is hidden from other transactions until it is complete.
      • durable::=A transaction, once completed, is never lost -- even if things break down or fail.

    32. database_mapper::=The class of the object determines what data needs to be stored so define objects for each class to handle the tables.

    33. cache_management::=Databases should manage their own caches.

    34. hide_SQL::=Put all the SQL in one object -- a singleton -- and keep it separate from the rest of the code. Treats SQL as an external entity with its own secrets. See Parnas.

      Exception Principles

    35. Convert_exceptions::=If you can not handle an exception then convert it to a higher level exception.
    36. Name_the_problem_not_the_thrower::=name exceptions to indicate what is wrong not where it came from.
    37. centralize_error_logging::pattern. Have a single object that is responsible for recording bad things.
    38. standard_error_dialog::pattern. Have a standard user interface for reporting and sorting out errors.

      OO Principles

    39. OO::=Object Oriented Principles, including abstraction, extension, polymorphism, etc.
    40. OID::=Objects should know their own identity... and this can be expressed as a simple data item and stored in data tables, and hidden from the user.

    41. abstraction::OO=Variables and parameters should be declared as reference or pointers to abstract data types whenever possible, and containers as holding pointers to abstractions. Also known as Aim high -- allow your pointers to refer to abstractions and then they can point to many special kinds of object. For example(in C++):
      1. Declare variable abstract and assign adrees of concrete:
         		List * example = new SpecialKindOfList(....);
         		Person * dick = new Faculty(....);

      2. Declare parameters as refs to abstractions
         		void zark(List &w){....}
      3. Declare containers as containing pointers to abstractions:
         		map<string, Person*> people;
         		people.insert(string("Dick"), dick);

    42. extension::OO=Extend classes rather than reinventing the wheel.

    43. polymorphism::OO=let objects sweat the details for you. See GRASP Polymorphism

      Other Principles

    44. Parnas::=place different decisions in different modules, for example
      • 1971: Put input, output, and logic in separate modules that communicate by function calls.
      • Separate the physical from the logical.
      • Hide a data structure inside an Abstract Data Type.
      • Hide an algorithm behind a Strategy.
      • Hide external systems behind a Facade.
      • Hide libraries behind a Facade or an Adapter.
      • Hide SQL inside a package or object (hide_SQL).
      • Hide the User inside a User_interface (UI) Package.
      • Separate particular Applications from Business Logic and Domain.
      • Separate Model, View, and Controller. See MVC
      • Hide a RDBMS behind a simple OO persistence layer.

    45. CQS::=Command_Query_Separation,
    46. Command_Query_Separation::principle=Operations chould either do something and return nothing or return something and do nothing, NOT both,
      1. void doSomething(data);// nothing returned
      2. Type getSomething(data);//leaves everything the same.

      This dates back to the the theory of abstract data types and was inheritted by Meyer into objected oriented coding style. This principle leads to code that is slightly more verbose but very much clearer. It also reduces bugs by the pricple of Least_Surprise.

    47. Least_Surprise::principle=`Whenever you design anything choose a design that minimizes the surprises that the user may experience`. Henry Ledgard proposed this for programming languages but it also applies to user interfaces, common appliances, and object-oriented classes. Apple had a tendency to extend so that the user experiences occassional pleasant surprizes: the user does the wrong thing and the system does the right thing. This is also called
    48. DWIM::="Do What I Mean". This is a dangerous philosophy because it back fires.

    49. MVC::pattern="Model-View-Controller",
      • Separate Model (data + ...) from View(what the user sees...) from Control (what the user can do...). [ MVCinUML.gif ] (UML diagram of a View, Controller and Model packages)
      • Split Boundary, Control and Entity objects. [ icons.gif ] (Graphic showing common icons and stereotypes).
    50. FURPS+::requirements={Functional, Usability, reliability, Performanc, supportability, Implimentation, Interface, Operations, Packaging, Legal}, Grady92.

    51. KISS::=Keep It Simple, Stupid, see XP.YAGNI.

    52. PQRST::requirements={Purposes, Qualities, Realities, Systems, Techie}, from RJB.
      Net
      1. Purposes include functions and use cases and define why someone wants the software. To help us sell items to customers.
      2. Qualities are the needed properties of the software like security and performance criteria.
      3. Realities are domain models. We have the problem of integrating different views of the the real world
      4. Systems are the existing systems that we are replacing, using, modifying, and even competing with.
      5. Techie include technologies, techniqes, etc. and describe what and how we might construct the software -- the decisions we make: eg-- use VB and MySQL.

      (End of Net)

    . . . . . . . . . ( end of section Patterns and Principles) <<Contents | End>>

End