Click to See Complete Forum and Search --> : design patterns


ryadav
December 10th, 2004, 07:52 AM
Hi,

Please some one can give me an info about how to start learning design patterns.
As i am understanding bit by reading the design pattern book ( Eric Gama ).
Now i would like to appliy the learnings practicaly can some one help out in this.....


thanks,

Andreas Masur
December 10th, 2004, 08:29 AM
Well....reading the 'Design Patterns' is the best reference for design patterns. It also contains examples for every pattern....thus, I am not sure what you are asking about?

possom
December 10th, 2004, 11:02 AM
That book is where design patterns were born, and has made them as what they are today, so I agree with Andreas that it should be the first place to go.

If you would like to expand your knowledge in this area in more practical applications then do some searches in development sites... one example I found is http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp. Some articles/papers will expand on the concepts covered in 'Design Patterns' and may give you an idea how and when to implement them.

How this helps!

ryadav
December 19th, 2004, 03:54 AM
thanks to all, for considering my query.

reading and understanding the design pattern is good, but the concern is with where to apply right pattern in the application.

I am planning to automate the setting up of debugging environment using rational clearcase commands, I would like to implement in c++ there by applying the design pattern concepts.

Common steps we follow to set the debugging environment is as followes.

1. create view
2. create private branch
3. set the view
4. untar the binaries/libraries to the view directory.


my design is like this.

class abstract_debugengine{
public:
virtual void runengine () = 0;
filehandle* getfileobj (sstring envfile) { // read env variables from files into object }
};

// getfileobj inherits in all derived class we don't have to overwrite that.

class createview : abstract_debugengine {
public:
virtual void runengine () {
// use filehandle variable and run the engine to create view }
};


class privatebranch : abstract_debugengine {
public:
virtual void runengine () {
// use filehandle variable and run the engine to set private branch
}
};

class setview : public abstract_debugengine {
public:
virtual void runengine () {
// use filehandle variable and run the engine to set the view }

};


class untar : public abstract_debugengine {
public:
virtual void runengine () {
// use filehandle variable and run the engine untar binaries }

};


Is this design is correct ?

I am using the utilities like ( file handling, string handling ) which i have already implemented. But i didn't used any pattern concept for these.

my questions is what patterns fit for these utilities, i mean what pattern suits for
string handling functions, what pattern suits for file handling functions.
what pattern suits for the above requiremnet.


thanks,

ryadav
December 19th, 2004, 05:14 AM
I have applied Builder Pattern for Menulist ( as part of Debugging environment setup project ).

Is this pattern correct ? please feel free to provide comments on this....

string menulist[] = { "Create view",
"Create Private Branch",
"Set view",
"Untar binaries" }


/**************************************************************************
Director Interface [ parses the given data ]
**************************************************************************/


class Director {
public:
Director ( Builder* b ) {
setBuilder ( b ) ;
}

void setBuilder ( Builder * b ) {
bldr = b ;
}

void construct () {
for ( i = 0 ; i < menulist.length ; i++ ) {
bldr->VectorPush(menulist[i]) ;
}

}

private :
Builder *bldr ;

};


/**************************************************************************
Builder Interface [ Complex object implementation ]
**************************************************************************/


class Builder {
public:
virtual void VectorPush () = 0;
};

class BuilderPush : public Builder {
void VectorPush (string menudata) {
listobj.lst.push_back ( menudata ) ;
}

private;
Menulist listobj ;
};


/**************************************************************************
Abstract Menu This is for representation
**************************************************************************/

class AbstractMenu {
public:
virtual void DisplayMenulist () = 0;
};


class Menulist : public AbstractMenu {
public:
void DisplayMenulist () {
for ( i = 0; i< lst.size () ; i++ )
cout << lst[i] << endl ;
}
private :
vector<char*> lst, int i ;
};

/****************************************
main ()
***************************************/

main () {

BuilderPush one ;
Director dir( &one ) ;
dir.Constract () ;
}