This blog is about patterns in real life, design pattern, software patterns, the Gang of Four patterns and anti-pattern relating to Software Development.

Thursday, 22 March 2007

Example Pattern

[Blog 6]

Calendar Picker [ref.1]
Designed by Yahoo Developer Network

Problem
The problem is that there is a user who wants to look for or apply some notes on a particular date or range of date of a calendar.

Use when
The pattern will allow the user to easily apply a date or date range to the note that he will add to the calendar. In some situations the system itself will have to apply the date details to the note that is added to the calendar. By doing so, this will allow him to trace that particular note and sort the note by date or date order.

The most common type of note that will be added are meetings, appointments, events and so on.

Solution

There are a number of solutions which have been given which will allow the calendar to be used for adding or retrieving the notes that have been stored. Specific solutions have been given for specific problems like sorting by specific date, between different dates, selecting single dates and selecting date ranges.

Rationale
The interface provided by the calendar is quite common and it allows the user to make selection of dates by using a symbol.
Moreover the calendar also allows date and spelling checks and hence reduces the chance for users to make errors while entering their details.

Who can use it?
I think anyone who wants to schedule their work easily can use this design pattern.

[ref.1] – Design Patten Library, http://developer.yahoo.com/ypatterns/pattern.php?pattern=calendar#Solution

Tuesday, 20 March 2007

[Blog 5]

Comment about Coursework

The coursework consists of five questions and we have to complete four of them only.

Task 1 is based on Designing with Patterns, so we will be assessed on how well we can design prototypes and applications using the different Gang of Four patterns which are Strategy, Decorator and Adapter pattern. We also have to evaluate how effective those patterns are to the problem.
This task will help us to learn how to design systems by making use of patterns. Specific patterns can be applied to problems so we will have to learn quite a few patterns before we can decide which pattern (adapter, Decorator, Strategy…) goes where. We will have a better understanding of all the patterns and be in a better position to tell where and which pattern should be used and hence provide a more accurate solution to a problem. We will also be drawing UML diagrams to help us design the solution for the problem. So at the end we should gain enough knowledge to apply different patterns to solutions and be capable of arguing why a particular pattern has been applied to a problem.

Task 2 is all about Coding with Patterns where a programming language like Java, C++ or C sharp has to be used to create coding for designs in task 1. This task will help us develop our programming experience depending on the pattern that will be used. For each pattern the coding will be a bit different and some pieces of code might be used interchangeably. So, we should be in a position to comment on why we wrote the coding in such a way. And also, we will get more acquainted to documenting our codes which is quite important as this will eventually become a solution to a problem (pattern) and will be used by other developers, so it needs to be comprehensible.

Task 3 is all about software development and in this the author talks about patterns which can be used to design good websites. But actually, these are principles instead of patterns as argued in the wiki website. We will have to use the existing pattern and design it with another Pattern type (e.g. GoF). This will help us develop our skills where we have to examine existing systems where patterns have been used and try to do the same thing using a different pattern. It involves understanding the problem and trying to figure out the appropriate pattern from experience and form the solution using that new pattern.

Task 4 is about criticising patterns. An extract from a book is given which talks about anti-patterns who overlook the effort of authors of pattern. So here we have to write an essay about the quote that is given and describe what an anti-pattern is and what it is not and where it should be in computing. By doing this task it will enable us to see all the advantages of patterns and what people who are against patterns have to tell us about their disadvantages or usefulness. By researching on both pattern and anti-pattern we will have a better understanding of what a pattern is and how good it is to software engineering and what an anti-pattern is and also how useful it is to software engineering. At the end we will have a good understanding of pattern and anti-pattern.

Task 5 is about writing blogs about the lectures that we are having every week. After each lecture we have to compile some notes about what we understood and what we are learning. Other students can then have access to it which allows them to post their comments and ask questions if they are in doubt of anything. I think this is a good exercise as every one is online most of the time and students have another space where they can discuss and gain more knowledge about the subject.

[Blog 4]

This week we discussed about Abstract Factory. This is detailed below

Abstract Factory

An abstract factory allows groups of related or dependent objects to be created without specifying a specific class [ref.1]. The motivation behind using abstract factory is to allow portability of an application. If an application did not use abstract factory to implement a certain characteristic but used instantiation to do so, then it is difficult to change that characteristic at a later time. Specific characteristics can be easily implemented by defining the abstract classes and distinct subclasses. Instances of a class can be quarried but the user is not aware of the concrete class that is used.

Abstract Factory can be used when

- The creation, composition and representation of the product of a system should be independent of the system.
- Several families of products need to be configured in a system.
- Common related objects need to be used together.
- Products need to be classified under a common class library and their interfaces revealed and not their implementations.

The main participants of the Abstract Factory are [ref.1]:

AbstractFactory - declares an interface for operations that create abstract product objects
ConcreteFactory – implements the interface to create concrete product objects
AbstractProduct – declares an interface for a type of product object
ConcreteProduct – defines a product object to be created by the corresponding concrete factory and also implements the AbstractProduct interface
Client – uses only interfaces declared by AbstractFactory and AbstractProduct classes

The related patterns of Abstract Factory are;
- Factory Method (implementation)
- Prototype (implementation)
- Singleton

Advantages of using Abstract Factory
Abstract factory helps control classes of objects that have been created. So clients just work with instances through their abstract interface but are unaware of the roles and methods of creating objects. The class names do not appear in the client’s codes as they are eliminated.
A concrete factory class appears only where it is instantiated, so it can be swapped with other concrete factories to make different products.
It allows products to be consistent by making use of objects from only one family at a particular time.

Disadvantage of Abstract Factory
It is difficult to support new kinds of products because abstract factories have to be extended which is not easy. The interface of the abstract factory sets the products that can be created and so trying to add new kinds of products will mean that the interface of the abstract factory will have to be extended which in turn entail changing its classes and subclasses.



[ref.1] – Design Patterns CD Elements of Reusable Object-Oriented Software, by Erich Gamma et al, p.77 – 85.

Labels:

Tuesday, 13 March 2007

Software Pattern & FAQ

[Blog 3]

This week, the lecture was about Software Patterns, similar to Patterns except that Software Patterns is in terms of software development instead of real life. Software Pattern as everyone would guess is the idea which comes from Alexander’s construction engineering pattern. We also discussed about why patterns are used for software engineering and how it supports it.

Software pattern can be adapted in every stage of the systems development life cycle, for example, requirements pattern, analysis pattern, test pattern and so on, but we were told that we will be concentrating on design pattern only. To finish, more explanation was given to explain what a software pattern is not and the elements that we should not be confused of.

Pattern
Frequently Asked Questions

1. What is a Pattern?

A pattern is a solution which is applied to a specific problem which occurs repeatedly with time within a specific context. This means that a specific problem occurs in a particular environment and then a solution is applied to the problem to solve it.

2. Why do we have to use patterns?

We make use of patterns because they save a lot of development time, enable reuse of coding and solution and also they prevent guess work and provide more accuracy to find solutions for known problems.

3. Can the same solution be used for more than one problem?

Normally no, but in some circumstances it can be used to solve other problems as well because patterns can be adapted to solve similar problems in different situations. E.g. a Book library information system and a Video library information system.

4. If the problem is the same in 2 different occasions but the context is different, can the same solution be used for both problems?

No, although the problems are same, the same solution cannot be used if the contexts are different as the variables within each situation might be different.

5. Things you should not confuse of.

Patterns are not used where the solutions to problems have not been proven.
If a solution to a problem has worked only once then it is not a pattern as it should be usable to the same problem happening again in the future.
One solution cannot be applied to every situation where a problem arises, it can be applied to a certain specific problems only.
And finally, patterns do not represent solutions to all software design problems.

[Blog 2]

Software Pattern
Frequently Asked Questions

1. What is a Software Pattern?

A Software Pattern is a solution that is used to solve a recurring software engineering problem within a particular context. When software developers or programmers come across a software engineering problem which happened in the past, they solve that problem with the help of some software codes depending on the context of the problem and this is called a Software Pattern.

2. Why do we use Software Patterns?

Software Patterns are very useful for software development as it allows reuse of software solutions which reduces development time which is very important while developing a whole system. They also allow development through modularity as software problems are broken down into smaller and smaller problems and then a solution is found for each small piece of problem which makes implementation very easy as it does not affect other modules if it needs to be changed or removed.

3. Why use Software Patterns and not other methods for software development?

Software Patterns enable the developer to mould the solution according to their problem whereas other development methods have a generic solution which means that requirements have to be changed to match the solution.

4. Why are Software Patterns more preferred than pieces of codes from other software development methods?

Software Patterns gives more details and documentations on how the solution can be used and for what context it can be used whereas pieces of codes are just solutions for problems but there are no associated documentation on where and how it can be used.

5. What is the advantage of using Software Patterns in software engineering?

Software Patterns help novices to get knowledge from experts who developed the solution so instead of trying to come to a definitive solution to a problem by trial and error that solution (expert) can be used and the knowledge and understanding behind it can be grasped.

6. What Software Patterns are not?


Software Patterns are by no means: Business Objects, Frameworks, Algorithms, Components, Libraries and Packages. There are differences between a Software Pattern and those reusable elements.

Comments are most welcomed. Thanks