Structural Design Patterns

Adapter Pattern, Bridge Pattern, and Composite Pattern


Adapter Pattern

Adapter is used to adapt the behavior/functionalities of an existing class but with a different interface.
It can be implemented by two ways, by inheritance (also called class adapter) or by composition (also called object adapter). Either we can extend the existing class and use its functionalities in new interface method, or we can use a reference of existing class in new object for using existing functionalities. 

Example

  • We are making data bound UI components, which are implementing some of our proprietary interface to support the data loading/unloading. But UI components are already defined with Swing library so we want to use these and just want to bind them with data sources. Here we can extend our new components from existing Swing component and implement our data binding interface to it.
  • Use of Window Adapter while intercepting the window closing event. 

More Creational Design Patterns

Builder Pattern, and Prototype Pattern


Builder Pattern:

It separates the construction of complex object from its representation, so that number of different representations can be build based on the requirement. It is similar to factory pattern, but it does not return simple descendant of base class. The factory is concerned with what is made and the builder with how it is made. Factory simply returns an instance of related class of base type, but builder returns a composition of various classes depending on the specified state. 

Example

  • Editor Builder: Suppose you are creating a UI for workflow where a number of different types of nodes can exist. We need different editors to edit these nodes, which can be very complex in structure. Here we can use builder which can build the desired editor.  Even editors can vary in structure based on current state of system.


Creational Design Patterns

Factory Pattern, Abstract Factory Pattern, Singleton Pattern


Factory Pattern

It is responsible for creating the objects. As name depicts, it is a factory for creating any specific kind of objects. It abstracts the user from the details of creation mechanism, and also abstracts the actual implementation class of instantiated object. The only requirement is that the ‘object to create’ should be of some already defined type. The actual implementation may differ based on the current scenario.

Example

  • Maruti Car Factory Object: We can ask this object to return us a Maruti car based on any runtime parameter which defines its model like Wagon R, or Esteem. It is the responsibility of this factory object to return us required car implementation based on specific parameters.
  • Row Renderer Factory Object: We can ask it to return the renderer like structured row renderer, or a designable row renderer.


When to Use
  • We can’t decide in advance that which class of object we may require at runtime, however type is known. So the type is known but the implementing class may vary depending upon runtime scenario.
  • We want to localize the knowledge of object creation into some class, so that responsibility resides with one object only.
  • We want to make the system configurable and extensible and so want to program to interface not to implementation.


What are Core Design Patterns

What are design patterns?

  • Recurring solutions to design problems
  • Constitutes a set of rules to accomplish certain task in software development realm
  • Convenient ways of reusing object oriented code between projects and between programmers.
  • These describe how different objects should interact with each other without getting entangled with others data model and methods.
  • Started from early 1980, formally recognized in 1990(Helm) and 1992 (Enrich Gamma)
  • Suggests to program to an interface not to an implementation
  • Recommends composition over inheritance
Types of Core Design Patterns
  • Creational – These help us to create the objects in an optimized and flexible way, instead of directly instantiating the instances and give the flexibility to create the objects depending on the scenario.
  • Structural – Help us to compose a number of objects into a large structure in optimized way.
  • Behavioral – It defines and helps us to define the communication between objects and flow of control in the system.
Specific Design Patterns are described separately with other postings.

Struts Brief

Struts (http://struts.apache.org/) is a MVC framework and is used to implement the web application in Java using MVC design pattern. Struts provide a complete framework to divide the web tier in Model, View and Controllers.
  • Struts provide action base classes to implement the controller at Web Tier, which will accept the request, call the business layer for required data or processing and will forward it to right view.
  • Form Beans, defined by Struts framework, carry the data.
  • JSP or HTML pages act as view. Controller i.e. action classes call business layer for data processing, set these as parameters in request/session and forward the request to view i.e. JSP or HTML page.

Class to override to make an action: org.apache.struts.action.Action

ActionForward - Override execute method in extended class to forward the request to some other page.

Use Case Brief

A use case is a description of something that a system does in response of any request from any other automated system or actor.

How to write:

  1. We should write the use cases in business terms, not technical ones.
  2. Any business person should be able to understand the use cases without the help of any technical personal.
  3. Technical design assumptions should not be made at this stage.
  4. Use cases can also serve as a contract between business and development sides of any organisation.
  5. Use case text should begin with "The system (or application) will". If a use case can not be started like this, it means it is either not a valid use case or is a part of another use case.
  6. Explicitly list all the affected actors in the use case.

Trip to Dalhousie - Khajjiar - Chamba



This is our first trip to Dalhousie - Khajjiar - Chamba (of four days duration) in Sep 2009. Dalhousie and Khajjiar are famous for their untouched natural beauty and peaceful environment. It is a very peaceful place to spend few days away from City Life, in the vicinity of nature. Here are a few details of these places.




Traveling Directions:

Route: Delhi > Ambala > Ludhiana > Jalandhar > Pathankot > Banikhet > Dalhousie
Driving Directions can be found at http://www.oktatabyebye.com/travel-directions/driving-directions-from-New_Delhi-to-Dalhousie.html

Treatment for Warts

wart (also known as verruca) is generally a small, rough tumor, typically on hands and feet but often other locations, that can resemble a cauliflower or a solid blister. Warts are common, and are caused by a viral infection, specifically by the human papillomavirus (HPV) and are contagious when in contact with the skin of an infected person. It is also possible to get warts from using towels or other objects used by an infected person. They typically disappear after a few months but can last for years and can recur. (From WIKI)

Important links:
You will get almost all the information from above mentioned links for warts description, and their remedies. Thanks to their writers.

Warts are generally caused by a virus named as HPV. It can spread by direct touch, by clothes, or by water like during swimming etc.

Expression Engine


What it will do -

This system is defined to evaluate various kind of expressions.

With the basic version, it is capable of evaluating the mathematical, logical and object property expressions. However system can be extended easily to evaluate any new type of expression like XML. The extensibility comes from the definition of grammar, parsing rules and expression implementations in the configuration files (XML based), which can be extended easily.

System does have support for evaluating the functions and variables. User just need to provide the helping classes having implementation for functions and variables. Any new implementation can be plugged easily to the system.

Libraries for PHP Enterprise Level Applications

Following is the list of tools 'good' for Enterprise Level PHP Application:

  • Zend – Framework – Collection of libraries and components in PHP – Best suited and recommended for enterprise level projects (http://framework.zend.com/)
  • ExtJS -  Java Script Library – Will be used mainly for Portal look of dashboards (http://www.extjs.com/deploy/dev/examples/portal/portal.html)
  • Phing – Build Tool for PHP Projects – Will be used for build environment of project (http://phing.info/trac/)
  • Zend Test with PHPUnit – Unit Test Case framework for PHP projects – Will be used for unit test cases (http://phpunit.sourceforge.net/)
  • Zend Log or Log4PHP or Pear Logger – Logging Tool (http://incubator.apache.org/log4php/index.html, OR http://pear.php.net/packages.php)
  • Eclipse PDT with Zend Eclipse Extensions – As development IDE (eclipse.org, AND http://www.zend.com/en/community/pdt)
  • Tomcat as web server
  • Zend DOJO Library, Scriptaculous – For Java Script Components and various effects at UI
  • Zend SOAP library – For web services / SOAP handling in project
  • Zend ACL library – For Authorization on various resources, roles based security
  • Zend Auth Library – For HTTP or LDAP based Authentication
  • Zend Cache – For caching various resources and optimization of system speed
  • Zend Config – For maintaining the configuration of the applications
  • Zend Controller and Front Controller – As controller in the application (MVC)
  • Zend DB or Pear DB library – For database accessor (DAO)
  • Zend Locale – For localization
  • Zend Mail – For mailing functionality
  • Zend Paginator – For Pagination in application
  • Zend PDF or Issuu PDF Reader if it can be used – For PDF library (http://issuu.com/services/customize/)
  • Zend Search – For searching functionality in the application
  • Zend Session – For application session management
  • Zend Memory Manager – For memory management