Objectives:

•        Create working definition of a pattern
•        Review where the concepts of patterns evolved from
•        Introduce the example that will be used in class
•        Discuss the Model View Controller architecture
•        Investigate how patterns are described and taught
•        Provide a list of resources for further education


Overview
Patterns are commonly discussed, used for design and implementation and constantly come up when create
J2EE™ applications.  Understanding what a pattern is not very difficult, but understanding how to use and
apply them can me more challenging.  As this class progresses we will introduce a handful of patterns and to
understand how they fit into J2EE we will work through a simple application.  This application is provided
to give a better understanding of how patterns work together to create applications.
In this chapter we will lay the ground work for learning a set of patterns.  Each pattern will be presented
separately, but they will fit into a larger example application.  We will define a patterns show you how they
will be presented.  We also will quickly review J2EE and build a short list of good resources for work beyond
this class.


What is a Pattern?                                                                                
•        A pattern is a solution to a problem with listed advantages and disadvantages to that solution.
-        Patterns and pattern languages evolved from a non-software design application.
-        Patterns started to become popular when the book “Design Patterns Elements of Reusable Object-
Oriented Software” came out.  This book is often called the Gang of Four or GoF pattern book.
•        Breaking down the definition a pattern you see four parts.
-        The name of the pattern.
-        A problem or a Context.  The where portion of the definition.
-        A solution that fits into that context.
-        A discussion of advantages and disadvantages to using this solution.
•        The definition of a pattern does not limit it to a software design or architecture context.
-        In a more abstract context a pattern to requirements gathering or lawn mowing could be defined.
-        For this class we will stick to object oriented design patterns, which is what most people mean when
they say pattern.

•         A pattern has little use if the context is rare.
-        Patterns are definitions to commonly encountered problems.
-        They are not meant to be rare or uncommon even, they are very common.
•        Solutions to problems aren’t new, patterns give us a way to name is discuss solutions.  This makes
patterns a way to communicate.
-        Naming patterns give the educated developer/architect a language to help communicate design,
architecture and implementation.
-        “Patterns speak” is common among J2EE developers and has proven to be an effective way to
communicate complex design.
-        Those who don’t use “pattern language” solve many programming issues identically (or nearly
identically) to those who do.  
•        Learning Patterns for use in design, implementation and architecture of J2EE becomes a task in
understanding a new language.
Why are Patterns becoming popular?                                        
•        Patterns give designers a common language which makes communicating design ideas easier.
•        Patterns help you as a designer recognize similar problems and decide what solution is best.
•        Patterns expose you to other peoples designs without needing to understand the whole application.
•        Patterns are not a new concept.  Patterns represent a formalization of terminology.
-        You don’t need to understand all patterns to use them.
-        You have probably used them without knowing, learning the terms helps with communication.
-        Formalizing terminology (giving a name to a concept) helps everyone understand that concept.
•        Object or component reuse has had less than 100% success.  Many objects created for reuse are
discarded or not found by the next programmer that needs the same functionality.
-        Patterns represent a reuse of design that is simple, powerful and very reusable.
-        Those who learn patterns usually find they make design easier by identifying common solutions.  
-        Those solutions are reused many times.
Pattern History                                                                                        
•        Before going into any one pattern you should know some of the basics of where the idea of a pattern
came from.
•        The pattern concept was borrowed from civil engineering.
•        Patterns became popular after the release of the “Gang of Four” book which if often abbreviated to GoF.
-        The gang of four are Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
-        The GoF books is one of the most read books in all of software engineering.
-        The GoF book defines a set of patterns that are widely referred to and known.
•        In the last few years the number of patterns book, and resources have exploded.
-        Nearly every Java developer has heard of patterns and uses them.
-        There are dozens of pattern related books on the market.

J2EE                                                                                                
•        Java 2 Enterprise Edition™ (J2EE) is an extremely popular platform to develop business systems on.
•        We will not much time on J2EE, because basic knowledge of what J2EE is assumed for this course.
•        J2EE is a standard created to make it easier to develop component based systems.
-        J2EE promotes standard which allow companies to choose best of breed application servers reducing
the time to market for a solution.
-        J2EE promote cross platform/cross vendor component production.
-        J2EE has momentum and is a very common solution.
•        J2EE defines the relationship between many of the Java API’s.
•        J2EE defines a tiered architecture and specifies the contracts between the server vendors and those who
are creating the software components.

The Demonstration Application                                                        
•        To demonstrate one implementation of many of the patterns we will cover we will create a simple
application.
•        This simple application tracks members to a web site and what topics they are subscribed to.
•        This application is a stripped down version of a larger real world application.  
-        It was created to give students a concrete understanding of how a pattern is applied.
-        Patterns are abstract concepts, which can make simple enough topics hard to teach and learn.
-        The include examples are meant to help gain understanding of an implementation.
-        We will use Java in all code examples.  The same patterns could be taught with any Object Oriented
language, and the material presented is being applied to many languages.
•        The demonstration application we will used to teach the patterns is a very simple application.  
•        The application tracks a list of members and allows the members to login and change their information.

•        Administrators can do the following tasks:
-        Add new members
-        List all members
-        Delete members
-        Change personal information about members
-        Logoff of the application.
•        Non administrators can do the following tasks:
-        Logon to the system
-        Change their personal information.
•        For each member of this application we will track a few pieces of information.
-        Login
-        First Name
-        Last Name
-        Password
-        Address (2 lines, city state, zip, country)

•        The application will be a web application.  
-        We will need some kind of login screen.
-        We will need a main menu to help a user find functionality.
-        We will need a list to display all members.
-        We will need a person add/edit screen to allow changing of information.
•        Using this simple application we will create a web site that uses the patterns that will be discussed.
-        Singleton
-        Factory Method
-        Command
-        Controller
-        Façade
-        Business Delegate
-        Resource Locator
-        Data Access Objects
-        Data Transfer Objects

•        In addition we will combine the patterns to describe a few common architectures, or methods.
-        How to use patterns together is as important as any single pattern.
-        Some architectures such as Model View Controller are so common that the need to be discussed to
understand how the patterns are fitting into the larger picture.

Model View Controller Architecture                                                        
•        One commonly taught “pattern” is not really a pattern at all.  
•        The MVC or Model View Controller architecture is a combination of several patterns and is more of an
architecture than a pattern.
•        MVC separates concerns in a given application into three unique parts.
-        The model is the data and data manipulation rules.
-        The controller is the part of the application that controls how the application reacts to the user.
-        The View is how it looks.
•        The MVC architecture uses several patterns within it.
-        The Controller portion commonly uses the Factory Method pattern.
-        The Observer, Composite and Strategy patterns are used as well.

•        The demonstration Member Tracking application will apply a MVC architecture where the
presentation, data access and application control are separated.



     
-        The model will be the Data and the middleware objects used to manipulate the data.
-        The view will consist of JSP pages, with a completely HTML front end.
-        The Controller will be Servlets and supporting objects that manage the flow and reaction of the
application.
Continuing Resources                                                                        
•        This class can be thought of an introduction to patterns.  
-        We will not touch every pattern, or cover all the GoF patterns, it is not geared to pass some
architecture quiz or test.
-        It is not possible to learn how to apply patterns perfectly in a few days, patterns are studied and
learned through application.
-        There is no one correct way to apply patterns to any given application.  Designers often disagree on
which pattern is best in any given situation.
•        To continue your education in patterns you might want to look at one of the following resources.
•        Books:
-        “Design Patterns” – Gamma, Helm, Johnson, Vlissides
-        “Refactoring: Improving the Design of Existing Code” – Fowler, Beck, Brant, Opdyke, Roberts
-        “Core J2EE Patterns” – Alur, Crupi, Malks
•        Web Sites:
-        http://hillside.net/patterns/
-        http://martinfowler.com/articles.html#N30
-        http://c2.com/ppr/index.html
Design Patterns Tutorial
Table of Contents
Copyright (c) 2008.  Intertech, Inc. All Rights Reserved.  This information is to be used exclusively as an
online learning aid.  Any copying is strictly prohibited.
Courseware
Training Resources
Tutorials