« Home | Its a matter of Choice » | The Sinhagad Xperience ! » | On a Lonely Day » | Vanishing Moments! » | The fate of a Poet ! » | The Book of Life ! » 

Sunday, June 05, 2005 

Object Oriented Design !!! ..Is it me ?

Well tommorow I am supposed to give a lecture on OOD's Open and Close Principle...Sounds very wierd for the ppl and for me too ...of all things on earth i m lecturing on Programming ...Yes this is a fact and y this and y me have a simple answer .....Boss this is life you almost any thing can happen to you ...So this is it ....So what is the Open Closed Principle : Simply its having an abstraction for every class u derive so as u dont have to change the existing code of urs ..thats is working fine ....just put an abstraction layer for the extension of the code and keep on providing the functionlaties accordingly without changing the existing code ......So clearly defined the Open Close pRinciple says:
"Software entities like classes, modules and functions should be open for extension but closed for modifications."
Just take for the sake of example I am writting a program for a function that draws a particualr shape say triangle the code is working fine ....now when i try to provide a additional functionality of drawing a circle ... i will provide a switch case for circle ...and accordingly for every shape i add .....thereby making my code vulnerable ... mistakes and regression creeps in .......How to avoid this ...the answer lies in open close principle of designing......Make an Abstrack class shape having a draw function ......and then derive every shape from the base class .....isnt it simple ......isnt it the code is open for exptension and closed for modification ...........One of the very good para i read about object oriented concepts is smth like this .....
" Many of the concepts used in Object Oriented programming, are actually metaphors. We get so used to the metaphors that we forget they are metaphors. You are used to talking about a window on your program, but of course there is no such thing; there is just a rectangle with text and images in it. It looks like a window into your document so we call it a window. Of course, you don't actually have a document either, just bits in memory. No folders, no buttons — these are all just metaphors.
There are many levels to these metaphors. When you see a window on the screen, the window itself is just a metaphor enhanced by an image drawn on your screen. That image is created by lighting tiny dots on the screen, called pixels. These pixels are lit in response to instructions written in your program. Each instruction is really a metaphor; the actual instructions read by your computer are in Assembly language, low-level instructions that are fed to the underlying computer chip. These Assembly instructions map to a series of 1s and 0s that the chip understands. Of course, the 1s and 0s are just metaphors for electricity in wires. When two wires meet, we measure the amount of electricity, and if there is a threshold amount we call it 1, otherwise 0. You get the idea.Good metaphors can be very powerful. The art of object-oriented programming is really the art of conceiving of good metaphors. "
..............aptly said indeed ! What more i can say :)