Tuesday, 15 May 2007

Self Evaluation: Design pattern.....

Well it’s been an epic journey; it was whole new world to me. Exploring Design pattern and AntiPatterns were a best part of my educational life.

This blog is aimed to express my experience during this particular module.

I have learnt quite a number of things through out this module. I have outlined them into different titles and expanded it accordingly.

Design patterns

Throughout this module we have been introduced to design pattern. It was a new subject to me. I was familiar with java prior to design pattern. Upon the introduction to different design patterns my perception towards java programming has changed completely.

I have to mention about the GOF books and their ground breaking work on design pattern. The realization of the design pattern and its applicability on modern software development is indeed very much appreciated.

Apart from it, knowing about Adapter, strategy and decorator pattern were a blessing. Now I think twice before programming. I think about applying design pattern in programming rather then jumping on to code.

So it helped me a lot in terms of getting good program done with ease.

AntiPatterns

Fairly new term in the world of computing but without AntiPatterns the design is not completed. It is the natural counterpart of design pattern. AntiPatterns are getting popular because of its usability.

Blogging

To be honest I have very much liked blogging. Since the beginning of the classes I have been doing my blogging on regular basis. I have also liked the interactions between fellow class mates. Overall, I enjoyed the freedom of expressing my thoughts and opinions of learning design pattern.

Now in near future I would like to study design pattern further and explore the secret of all these patterns .

Wednesday, 9 May 2007

Website design patterns

Hey glad to be back, first of all thanks for all the comments.

This blog is aimed to explain and define my thoughts and understanding on website design patterns. Hey just to let you know, I am a freelance web designer. It sounds cool but to be honest I was not aware of website patterns before doing this module “design pattern”.

So far, we have had lots of examples of patterns being used in different aspects of life as well as computer industries to construct all these giants’ applications. Website is one of those trends which bought revolution in both in the internet as well as e-commerce.

Website patterns targeted to identify different elements and aspects of a general website where designer are vulnerable to make mistakes. Website is not like pure programming rather the exterior design as well as organizational aspects of computing is much more important to websites to make it appealing.

So my understanding of website patterns are a set of patterns deals with website related design and development issues from site types, user experiences, navigational and searching points of view.

Yes, the website patterns can be categorized into all these categories mentioned above and trust me each of the category can be extended further.

For example, according to welie.com, searching pattern for websites can be further extended into

· Advanced Search
· FAQ
· Help Wizard
· Search Area
· Search Tips
· Search Results
· Simple Search
· Site Index
· Site Map
· Topic Pages

Wow! That’s what I thought. It is interesting is not it?

Ok let’s look at the one of the pattern under searching category name as “Simple search”. I liked this pattern very much and thought illustrate it here the blog.
Simple search [1]

Problem
The users need to find an item or specific information.


Use when
Any web site that already has primary navigation. User may want to search for an item in a category. User might want to further specify a query


Solution
Offer a search * The search interfaceOffer search functionality consisting of a search label, a keyword field, a filter if applicable and a "go" button. Pressing the return key has the same function as selecting the "go" button. Also provide Search Tips and examples in a seperate page. A link to that page is placed next to the search functionality. The edit box for the search term is large enough to accomodate 3 typical user queries (typically around 20 characters). If the number of filters is more than 2, use a combobox for filterselection, otherwise a radiobutton. Search -- editbox -- for/in -- filter -- Go buttonor just...-- editbox -- Go button * Presenting search resultsThe search results are presented on a new page with clear label containing at least "Searchresults" or similar. The search function is repeated in the top-part of the page with the entered keywords, so that the users know what the keywords were. The number of "hits" is reported and the list of search results is organized; sorted or rated with the best matches at the top. When there are more than 10 results use a Paging mechanism. Each search result shows a link to the item itself and a snibbet of text to explain the item. Preferably that would a summary or abstract but can also be the first lines of text of the resulting item. The structure of a "result" typically shows: 1. Page Title2. Description3. Categorization4. URL, Size, Date * Keyword matchingIf more than one search term is used the search engine must handle them as follows: if no special separators are used (not including the space), the search is interpreted as an OR function, the results that match both terms are listed first. If special separators are used the search engine must be able to handle more than one convention. For example, sometimes the "AND/OR" separators are used but using a "+" or a "-", include and exclude, must also be handled correctly. The engine must also be able to handle spelling mistakes of at least one character.

Why
By using this setup the whole search becomes a sentence that reads like the search query.

Referenece

1. http://www.welie.com/patterns/showPattern.php?patternID=search

Tuesday, 3 April 2007

Anti Pattern

Anti pattern is a common term in design pattern. It rather like the both controversy and beauty of design pattern. Like any other things in the world there are positive and negative aspects of design pattern.

An antipattern is a frequently used, but largely ineffective solution to a problem. The term was originally used to refer to a pattern gone wrong.

From the programming and software development prospect anti pattern can be defined as

“Anti-patterns, also called pitfalls, are classes of commonly-reinvented bad solutions to problems” [1]

It is pretty handy concept in terms of avoiding risk and error intervene the solution. In a nutshell it can be used to for

Common practices to be avoided

Analogious programming practices:
Goto
Global variable


Anti pattern is rather closely tied up with managerial aspects of the organization. Initially, I had a look on the some of managerial issues closely related to anti pattern

Big ball of mud: A system with no recognisable structure

Blob: Too much functionality in a single design element

Gas factory: An unnecessarily complex design

Input kludge: Failing to specify and implement handling of possibly invalid input

Interface bloat: Making an interface so powerful that it is too hard to implement.

The basic formulae can for anti pattern can be defined as follows
Antipattern= (Problem +AntiPattern Solution+Refactory Method) in a contextAntipattern
Solution = Finding the root cause of that reoccuring problemRefactory
Method = Getting rid of this antipatterns
That’s it for today, I am still trying to explore more about Anti pattern and will be right back soon with more information in my next blog!! Until then have a good time. ;-)

Friday, 30 March 2007

Decorator Pattern

Today we have looked on one of the most popular design pattern “Decorator”. The name sounds interesting my initial understanding of this pattern were it helps us to decorate classes and subclasses in a typical OOP programming environment.



But below is what I have learned formally through out today’s lecture.

The Decorator Pattern is used for adding additional functionality to a particular object as opposed to a class of objects. It is easy to add functionality to an entire class of objects by subclassing an object, but it is impossible to extend a single object this way. With the Decorator Pattern, we can add functionality to a single object and leave others like it unmodified. [1]


A Decorator, also known as a Wrapper, is an object that has an interface identical to an object that it contains. Any calls that the decorator gets, it relays to the object that it contains, and adds its own functionality along the way, either before or after the call. This gives you a lot of flexibility, since you can change what the decorator does at runtime, as opposed to having the change be static and determined at compile time by subclassing. Since a Decorator complies with the interface that the object that it contains, the Decorator is indistinguishable from the object that it contains. That is, a Decorator is a concrete instance of the abstract class, and thus is indistinguishable from any other concrete instance, including other decorators. This can be used to great advantage, as you can recursively nest decorators without any other objects being able to tell the difference, allowing a near infinite amount of customization.
The Decorator Pattern attaches additional responsibilities to an object dynamically.
Decorators provide a flexible alternative to subclassing for extending functionality.

Quickly, had a look on the intent of this pattern which can give us initial ideas about this pattern and why it is for?


Intent [2]


Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. Client-specified embellishment of a core object by recursively wrapping it. Wrapping a gift, putting it in a box, and wrapping the box.

Structure of Decorator

As we can see it from the UML notation of the decorator the client is always interested in CoreFunctionality.doThis(). The client may, or may not, be interested in OptionalOne.doThis() and OptionalTwo.doThis(). Each of these classes always delegate to the Decorator base class, and that class always delegates to the contained "wrappee" object.


Rules of thumb [3]

To explore more I have also gone through GOF’s book and found some interesting comments on this pattern. Below is the list of couple of them

Adapter changes an object's interface, Decorator enhances an object's responsibilities. Decorator is thus more transparent to the client. As a consequence, Decorator supports recursive composition, which isn't possible with pure Adapters. [GoF, p149]

Adapter provides a different interface to its subject. Proxy provides the same interface. Decorator provides an enhanced interface. [GoF, p216]

Decorator lets you change the skin of an object. Strategy lets you change the guts. [GoF, p184]

Composite and Decorator have similar structure diagrams, reflecting the fact that both rely on recursive composition to organize an open-ended number of objects. [GoF, p219]

Conclusion

So far I think decorator is a very important design pattern can be applied in the PAFSD coursework. The amount of work can be perceived by decorator pattern is beyond the imagination. I have tried to learn how decorator pattern has been applied in java and came to know that JAVA I/O is a solid example of decorator pattern in java. Now that I have learnt about decorator pattern my aim would be to implement it in my PAFSD task 2.

References:


1.http://www.exciton.cs.rice.edu/JavaResources/DesignPatterns/DecoratorPattern.htm
2.http://www.oreilly.com/catalog/hfdesignpat/chapter/ch03.pdf
3.Design Patterns: Elements of Reusable Object-Oriented Software By Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides

Monday, 26 March 2007

Adapter Pattern

Introduction

This particular pattern seems to very interesting and goes with the core concept of java. I really liked the concept.

In today’s lesson we have discussed about how a pattern is preserved in a catalogue generally. I was curious to find out if all this preserving elements were all necessary to describe the nature of a pattern. So I picked one of the GOF pattern which adapter. I am trying to determine the importance and applicability of these elements in adapter.

Adapter Pattern

Adapters are used to enable objects with different interfaces to communicate with each other.
Adapters come in two flavors, object adapters and class adapters. These two methods embody the difference between the use of inheritance and composition to solve problems.
This pattern is used when;

·User wants to use existing class but the interface doesn't match user needs
·Creating a class that communicates with unrelated classes
There are two types of this pattern; Object Adapter pattern and Class Adapter pattern
Object Adapter Pattern
In this pattern the adapter holds the instance of the class it wraps and makes call to the instance of the wrapped object. [1]
Class Adapter Pattern
The class adapter pattern uses the concept of multiple inheritance. The adapter is created inheriting interfaces from both the interface that is expected and the interface that is pre-existing. [1]

Adapter Pattern Template [2]

Intent
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Also Known As
Wrapper

Motivation
Sometimes a toolkit or class library can not be used because its interface is incompatible with the interface required by an application
We can not change the library interface, since we may not have its source code. Even if we did have the source code, we probably should not change the library for each domain-specific application

Structure
A class adapter uses multiple inheritances to adapt one interface to another:
An object adapter relies on object composition:

Applicability
Use the Adapter pattern when You want to use an existing class, and its interface does not match the one you need. You want to create a reusable class that cooperates with unrelated classes with incompatible interfaces

Implementation Issues
How much adapting should be done?
Simple interface conversion that just changes operation names and order of arguments

Totally different set of operations
Does the adapter provide two-way transparency?
A two-way adapter supports both the Target and the Adaptee interface. It allows an adapted object (Adapter) to appear as an Adaptee object or a Target

Adapter Pattern Example

public class ButtonDemo {
public ButtonDemo() {
Button button = new Button("Press me");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doOperation();
}
});
}
public void doOperation() { whatever }
}

Button objects expect to be able to invoke the actionPerformed() method on their associated ActionListener objects. But the ButtonDemo class does not have this method! It really wants the button to invoke its doOperation() method. The anonymous inner class we instantiated acts as an adapter object, adapting ButtonDemo to ActionListener!

Conclusion
Class adapters are a lot flexible than object adapters in that they involve fewer classes and are useful if total decoupling of the client and adaptee is not needed.
References:
2.Design Patterns: Elements of Reusable Object-Oriented Software By Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides

Tuesday, 20 March 2007

Critical Evaluation of PAFSD Coursework

Task One: Designing with pattern

In task we have been asked to design an application which stores customer records and enable users to view the customer records in variety of ways.

According to course work we have been agreed the option to use all of the following patterns

Strategy
Decorator
Adaptor

In first instance I see it as limiting the student to design the applications in such away that using the pattern mentioned above becomes mandatory. It seems like we are only focusing on the patterns mentioned above which narrows down the scope of learning.

In the mean time, it is not possible to cover all the patterns so it is viable to be selective and use the patterns has been suggested.

According to the industry and the software developer the three patterns mentioned above are very useful and handy.

Task 2: Coding with Patterns

It’s a good opportunity for a student to probe him/herself especially those with an interest in programming. I am interested in programming specially java. It is always been my dream to explore the beauty of programming language such as java. In this work I have the opportunity to learn about pattern and their implication in programming application. My initial understanding about pattern is it might help a programmer to beautify and structure their program.

Before learning about design pattern I used to jump on to the code before thinking or analyzing about the given scenario which is of course not a good programming practice but design pattern given me a new thought of thinking and adopting patterns for solving problems. I am looking forward to use my learning in this case when I will be writing the codes

Task 3: Patterns and software development

Out of all the tasks, I have liked this particular task as like most of the computing student I am interested in web and graphic designs. What more is interesting I am a freelance website designer (www.immysnet.co.uk) so I can definitely learn pattern in website from this task and apply in my practical life.
I had a look on the website pattern mentioned in course work and realized that it is really important to have a pattern for personal website as it helps all the designer / user to follow guidelines and keep their website up to date. I am sure it would be beneficial to have a adopt design patterns for website as the market demand for web based business are on high.

Task 4: Critiquing Patterns

To me this part of the course work is the trickiest one. I see “Anti pattern” as a controversial topic in design pattern but in the mean time I find beauty where there is controversy! Life is not all rosy so as the design pattern.

If I were to do this task I would definitely enjoy the challenge but at the I would like say what my friends says about anti-pattern

“If you are on target there are plenty of marks can be scored and on the other hand if you are off the track and get carried away it might proved to be a disaster.”

Task 5: Patterns Blog

Well, blogging is a new concept in learning now. To be honest I am enjoying blogging. It gives me the freedom of expressing myself and communicates; rationalize my opinions with rest of fellow mates via their blogs. New innovation of web 2.0 blog becoming popular and always been thinking of blogging but this course has given the option of doing so.

I think it’s a great inclusion and reflection of innovative idea to the course work.

Abstract Factory Design Pattern

Abstract!

“Abstract” sounds pretty technical but what exactly it means in English which might help to clarify the functions and meaning of abstract in design pattern. Well, I thought I might as well find out the synonyms of abstract and try to relate it to the design pattern. Below is the result, this is what I have found from answers.com

“Considered apart from concrete existence”

“Not applied or practical; theoretical”

These two lines of sentence did give me a bigger picture of abstract factory pattern. So let’s define it formally

Abstract Factory Design Pattern

I have been looking for some formal definition of abstract factory pattern and gather the following definition below
“An abstract factory class defines methods to create an instance of each abstract class that represents a user interface widget. Concrete factories are concrete subclasses of an abstract factory that implements its methods to create instances of concrete widget classes for the same platform.” [1]

The definition sounds a bit technical but what I think about this pattern is it lets you take concern of the bigger picture and worry about the facts later. The main intent of this pattern is to 'provide an interface for creating families of related or dependent objects without specifying their concrete classes' [2].
Analogy

A fine analogy for this is a pasta maker. A pasta maker will make different types of pasta, depending what kind of disk is loaded into the appliance. All disks should have definite properties in general, so that they will work with the pasta maker. This specification for the disks is the Abstract Factory, and each specific disk is a Factory. We will never see an Abstract Factory, because one can never exist, but all Factories (pasta maker disks) inherit their properties from the abstract Factory. In this way, all disks will work in the pasta maker, since they all conform to the same specifications. The pasta maker doesn't care what the disk is doing, nor should it. You turn the handle on the pasta maker, and the disk makes an exact outline of pasta come out. Each individual disk contains the information of how to create the pasta, and the pasta maker does not.

Structure

The Abstract Factory defines a Factory Method per product. Each Factory Method encapsulates the new operator and the concrete, platform-specific, product classes. Each "platform" is then modeled with a Factory derived class.

Finally we can say the intent of this pattern are

1. Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

2. hierarchy that encapsulates: many possible "platforms", and the construction of a suite of "products".

3. The new operator considered harmful.


References:


2.Design Patterns: Elements of Reusable Object-Oriented Software By Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides [page: 87]