Tuesday 27 March 2007

Research on new pattern: Datetime Design Pattern (blog 6)

Dr.Sri asked us to do some research on more patterns apart from the one we are studying in our unit. I was looking on the internet trying to find some new pattern and came across DateTime Design pattern
Datetime Design Pattern
Why
This design pattern is used to make human readable datetimes to be also formally read by the machine. The needs arises as a result of solving the practical need for human readable dates for hCalender (hCalendar is a simple, open, distributed calendaring, based on the Calendar standard).
Where & How it is used
Datetime design pattern is used in hCalendar is something like this:
Date Time
where foo is the name of the class which is being applied to this date/time, the title of the is an ISO 8601 date/time and "Date Time" is a friendly representation of the same date/time. [1]
Reference:
[1] Where Datetime deisng pattern is used
http://microformats.org/wiki/datetime-design-pattern

Thursday 22 March 2007

Comment on the Coursework (blog 5)

Well finally we got the coursework and thanks to Jane chandler who came to our college and gave us very valuable information about the coursework.
When I first looked at the coursework when it was handed to me and to all classmates I was scared that how I am going to do it because I have other course work to do as well, anyway when I came to know the submission date for this course work I was a bit relaxed after that.
The course work seems to be alright, doesn’t look very easy neither very hard but It is lengthy.

TASK1 (UML Designing)

If we talk about the task 1 which is based on UML designing in terms of Strategy, Decorator and Adaptor patterns. First of all what I think that it is not possible for anyone to complete this task unless you understand how UML diagrams are designed. If you know how to design UML diagrams than this Task is easy to attempt because we just have to come up with four UML diagrams and of course we need to design them by adapting the above three mentioned design patterns and apply them to the prototype of customer records.

TASK2 (Coding) & TASK3( Patterns and Software Development)

I am making my mind to do task 2 (coding) but still confused I might attempt task 3 which is a bit theoretical. Although there is much possibility of doing the coding task because I have been programming since more than two years but I haven’t done programming using patterns. Task 3 is not tough as well but I am thinking what tasks should I attempt.

TASK4 (Essay writing)

I think this is most difficult question in this course work in which we have to write an essay about anti patterns and write our point of view on anti patterns. This task could have been easy if there was no specific scenario given. Writing an essay of 600 words reminds me of my school days when I use to write essays on different topics but never got a chance to write an essay related to computing and it is really hard to get good marks when you are writing an essay. I am looking forward to do my level best to take this task as my 3rd task.

TASK5 (Blog)

I love blog because we just have to write whatever we understood from the lecture given in the class so there is not as such research involved in it. So I am happy to do the blog task. Basically in this task we just have to write what we learnt from our lecturer on each class. So we didn’t understand the lecture very well the other way we can do a bit research online about the topic which was taught in the class and then write it in our own words or do referencing.

Overall,Coding and the essay writing are the tasks in which we have to be very careful how are we using patterns and what are we writing about patterns, rest I think its straight forward.
Please give your comments

Wednesday 14 March 2007

Abstract Factory (Blog 4)

The next blog on which we were asked to understand and do research is Abstract factory. I have looked in to many websites, tried to get as much knowledge as I can and now I am going to write what I understood about Abstract factory..!
The Factory Pattern known as Abstract Factory is used to facilitate class instantiation. In the Abstract Factory pattern, a special class, called a factory, is created whose main aim is to create instances of a class.
The factory method pattern is like defining an agreement for the creation of a given type of classes
  • An abstract factory is an object creator.
  • It can produce different types of objects.
  • Each object that it produces is recognized by receiver of the object which is created only by the interface of that object, not by the object's real implementation.
  • Objects which are produced by abstract factory are related to each other or you can say they belong to a common family

Benefits

Abstract factory eliminates the need of classes to bind in to the code. The code deals with the interfaces, therefore it is possible that I can work with any class that implements an interface.
It also allows the subclasses to give an extended edition of an object because it is hard to create an object within the class but It is more easy to create an object in the client directly

Thursday 8 March 2007

Criticism on one the Patterns (Blog 3)

Singleton

Going through briefly on 23 patterns the one I liked and would like to share is Singleton pattern. The reason of choosing this pattern is that it is easy to understand and more explainable. After doing research on internet about this pattern according to my understanding the definition of single pattern is:

“The singleton design pattern is designed to limit instantiation of a class to one object”.

Singleton is most likely the most commonly used design pattern. The main aim of singleton pattern is to provide one instance for each class and a gateway where everyone can access in to it. There are many situations in which a singleton object is necessary: a GUI application must have a single mouse click, an active modem needs one and only one telephone line, an operating system can only have one window manager, and a PC is connected to a single keyboard.

CRITICISM

Intent
The main intention of a Singleton is to make sure to have only one instance of this class with a global point of access to it, thus avoiding the use of global variables and conflicts among them.

Motivation
Sometimes! Some classes should only have one instance, and be available from everywhere; here singleton pattern can be applied. So the instance which is created by a class will have global access and the constructor of the class blocks more than one instance to be produced.

Applicability
Singleton pattern can be used in this case when:

There should be only one instance of a class and can be accessed by many clients from a well known point. If some global object is a client of another one, the latter may not be destroyed until the former terminates. No distinction between individual and composed objects.

Structure
Structure of Singleton Pattern is in the form of a diagram in which the structure is described of how the class can be limited to one instance.

Collaboration
The thing I like about singleton is that and would like to share is that Clients get the right to access a Singleton instance only through the operation which is performed by Singleton's Instance.
Consequences
The Singleton pattern has several benefits:
1-Each instance is controlled properly in such a way that it limits the clients control on it depending how and when they try to access it.

2-Limits the size of name space. As we all know now that singleton pattern creates only one instance of a class therefore it also provides perfection over global variables.. It avoids polluting the name space with simultaneous access. There is a possibility that there could be a subclass of a Singleton class and It is very easy to configure a program with the help of an instance of the extended class.

Implementation
To implement a Singleton patter, class is created with a method which creates a new instance of the object if the object is not there. If an instance is already there it simply returns a reference to that object. To prevent the object to be instantiated in any other way, a private or protected constructor should be created.
Sample Code
Here is a sample of how singleton is used in programming.

public class Singleton
{
private static Singleton NEWINSTANCE = new Singleton();
private Singleton() {}
public static final Singleton getInstance()
{
return NEWINSTANCE;
}}


Known-Uses
In this section, the known uses of this pattern can be understood with the help looking in to examples.
Suppose if we are authorized to have only one license of a particular database, Singleton takes care that only one connection has been to the database to access records and suppose if we had more connections to the database then singleton can also adjust more than one connections. [1]

Related Patterns
Singleton pattern is mostly used with Abstract Factory, Builder, and Prototype. The Singleton is a bit similar to a Cache manager, but with one object.
Reference:
[1]Example of Singleton