Friday, January 30, 2009

What are Design Patterns?

Sitting at your desk in front of your workstation, you stare into space, trying to figure out how to write a new program feature. You know intuitively what must be done, what data and what objects come into play, but you have this underlying feeling that there is a more elegant and general way to write this program. In fact, you probably don’t write any code until you can build a picture in your mind of what the code does and how the pieces of the code interact. The more that you can picture this “organic whole,” or gestalt, the more likely you are to feel comfortable that you have developed the best solution to the problem. If you don’t grasp this whole right away, you may keep staring out the window for a time, even though the basic solution to the problem is quite obvious. In one sense you feel that the more elegant solution will be more reusable and more maintainable, but even if you are the sole likely programmer, you feel reassured once you have designed a solution that is relatively elegant and that doesn’t expose too many internal inelegancies. One of the main reasons that computer science researchers began to recognize design patterns is to satisfy this need for elegant, but simple, reusable solutions. The term “design patterns” sounds a bit formal to the uninitiated and can be somewhat offputting when you first encounter it. But, in fact, design patterns are just convenient ways of reusing objectoriented code between projects and between programmers. The idea behind design patterns is simple-write down and catalog common interactions between objects that programmers have frequently found useful.

The pattern concept

As mentioned above Design Patterns can be described as suggestions for object-oriented software design. Patterns are not trivial and they are not represented by features that are built into the language as inheritance for example. A pattern solves a certain type of problem in a specific context and gives a concept for the collaboration of objects, classes and methods. Although it is intended to support the programmers work it is more a layer of abstraction and meets in this point the basic concept of program design. The most compelling motivation behind this is to separate things that change from things that stay the same. Following this principle reduces the effort to make modifications on parts that could actually be unchanged - which causes lower costs and makes programs easier to understand. One of the main features of Design Patterns is that each pattern has a known name. The consistent use of these names and the patterns belonging to them increases the ability of each programmer in his work and also helps to communicate with his colleagues by the use of a common vocabulary. Terms like Factory, Iterator or Singleton are used quite often in software projects and should have the same meaning for all project members.

The authors of Design Patterns – Elements of Reusable Software divide patterns into three types: creational, structural and behavioural.

Creational Patterns give control over instantiation of objects. Using this type of pattern the programmer doesn’t need to instantiate objects directly and gives the program the ability to decide, which objects need to be created for a given case. Patterns belonging to this type are The Factory Pattern, The Abstract Factory Pattern, The Singleton Pattern, The Builder pattern and The Prototype Pattern.

Structural Patterns help to compose groups of objects into larger structures, such as complex user interfaces or accounting data. Examples for Structural Patterns are The Adapter Pattern, The Brdige Pattern, The Composite Pattern, The Decorator Pattern, The Façade Pattern, The Flyweight Pattern and The Proxy Pattern.

Behavioural Patterns help to define the communication between objects in the system and how the flow is controlled in a complex system. Known Behavioral Patterns are Chain of Responsibilty, The Command Pattern, The Interpreter Pattern, The Iterator Pattern, The Mediator Pattern, The Memento Pattern, The Observer Pattern, The State Pattern, The Strategy Pattern, The Template Pattern and The Visitor Pattern.

This post provide just an introduction to the world of design pattern.Stay tuned for more.

Saturday, January 10, 2009

Code Search Engines!!!

Searching for help is the human tendency, so is true for Developers (ofcourse, Developers are also humans:)).But as they say searching is an art in itself so far that the good developers are those who mastered the art of searching on Google or any other search engine. But most of you will agree with me that it is often quite difficult or rather cumbersome to search the right code snippet that will save that at least half an hour for that coffee break :). So, what about dedicated code search engines? sounds interesting, so here we have the complete list of the code search engines that I found out,ofcourse by searching...

codase.com

bytemycode.com

csourcesearch.net

google codesearch

freshmeat.net

gotapi.com

krugle.org

merobase.com

oreilly.com

microsoft.com

quickref.org

sourceforge.net

codeproject.com

Happy Coding!!!

Wednesday, January 7, 2009

Create Nested Subfolders in VBScript

Here is the simple vbscript to create nested subfolders depending upon the number entered by the user:


Dim fso,flr,resp,subFoldernum,nestedFoldernum,stuffTowrite,dateStamp,folderPath
dateStamp = Date()Const ForWriting = 8
stuffTowrite = "Whatever you want written " & dateStamp
Set fso = CreateObject("Scripting.FileSystemObject")
resp = InputBox("Enter Folder Name","Create Folder")
subFoldernum = InputBox("Enter Number of Subfolders","Create SubFolder")
If IsNumeric(subFoldernum) then
nestedFoldernum = InputBox("Enter Number of folders you want to create in the Subfolders","Create Nested SubFolders")
If IsNumeric(nestedFoldernum) then
Set Fldr=fso.createfolder(resp)
For x = 1 to subFoldernum
Set Fldr=fso.createfolder(resp & "\SubFolder"&x)
For y = 1 to nestedFoldernum
folderPath=resp& "\SubFolder"&x&"\nested"&y
Set Fldr=fso.createfolder(folderPath)
Set WriteStuff = fso.OpenTextFile(folderPath & "\test.txt", ForWriting,true)
WriteStuff.WriteLine(stuffTowrite)
WriteStuff.Close
Next
Next
else
msgbox("Whatever you submitted,is not a numeric value.")
end if
else
msgbox("Whatever you submitted,is not a numeric value.")
end if