Why do we need Abstract Class


Why do we need an Abstract Class, when all the functionality can be achieved
through Base Class and Interfaces?

We write abstract class to define some abstract methods along with, some common methods which can be used by other subclasses. So we can do one thing, the common methods we can define in a Base class. And abstract methods we can define in Interface and the class need it will implement the interface (or the Base class above will implement the
interface).

In this way we can achieve both the functionality. Then why do we need Abstract Classes?

Answer: 

Let us consider a scenario where:


  • We are having a framework with some framework specific methods in core implementing classes, like initialize, uninitialize etc. 
  • We want some work to be implemented in these methods by base and implementing classes both, like 
  • Some common code in base class 
  • Some specific code in extending class 
  • However the sequence of calls for these code segments should be fixed i.e. as per framework assumptions 
Let us take example of initialize method


Class abstract AbstractClass {

Public final void initialize ()
{
      // initialize framework specific items like service locators in
abstract class
// initialize object specific factory in abstract class
// initialize any other resource which is required to be initialized before
any other item of object in abstract class
      InitializeUI ();
// initialize DTO Cache in abstract class
InitializeDTOBindings();
// show UI

}
Public void abstract initializeUI ();
Public void abstract initializeDTOBindings ();

}
Now the extending class is forced to implement the two abstract methods, which framework wants it to extend. However framework still has the control on sequence of method calling and also providing some common implementation. This common implementation is very important with base class, as all the
developers in team may not be mature enough to learn and follow the framework protocol. 

So here abstract class is helping us to enforce the framework protocols. 

More Behavioral Design Patterns

Observer Pattern, Strategy Pattern, Visitor Pattern


Observer Pattern

It enables one or more objects to observe the states of one or more other objects. By implementing this pattern, one object request other object to intimate it for any change in a specific state which enables the system to refresh or act dynamically based on any state change anywhere in the system.

Here the object which is producing the events for state change is called observable and the object capturing the events is called observer.

Example

  • If an object contains the data for system and two different objects like JList and JTable are responsible to display this data in required format. Here JList and JTable can register themselves as observer to object containing the data.  So that any change in data can be captured and corresponding change can be made in view.

Behavioral Design Patterns


These patterns are more specifically concerned with communication between objects.

Here are Chain of Responsibility Pattern, Iterator Pattern, Command Pattern and Mediator Pattern.

Chain of Responsibility

It allows a number of classes to attempt to handle a request, without any of them knowing about the existence or capabilities of other classes. So a lose coupling occurs between these classes and the request object passed to these classes is the only common link.

The request is passed through these classes until any one of these handles this request. Generally once handled, no other classes are visited. But a distorted form of this pattern allows more than one class to handle the request and process it, like servlets filters.

Example

  • A help system, which can take the request for help from specific portion of UI. A chain of different help handlers in help system can try to handle this request and if any handler is successful to handle this request, it will do the processing. Further no handler will be invoked by core system.
  • We have the requirement to process some of the data from flat files and based on this data and some other parameters to the system, have to feed this data to database. The processing flow may vary depending on type of data and supplied parameters. Here distorted form of chain of responsibility can be applied.

Decorator Design Pattern

A decorator also known as wrapper is an object that has an interface identical to an object it contains. Any call that the decorator gets, it relays to the wrapped object and add its own functionalities along the way, either before or after the call. 

Example

  • If we need to draw different borders for toolbar buttons, and one border may be applicable to more than one button. This can extend beyond border i.e. to other functionalities like color, font size etc.
  • Suppose if we are developing our data access system and want to track each and every database call made by using java.sql objects, we can define decorator connection, statement and result set which can wrap any other data base object and can intercept the calls made by these. 


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.