Solved

Question on C++Design Pattern(Urgent)

Posted on 2006-11-23
1
246 Views
Last Modified: 2010-04-01
Hi Experts,

I have to do the following.  I am given a object X, and I want to convert them to different objects based on the data provided in the X object.  All the objects( B, C etc. ) that I wanted to create are derived from a common class A as below.

class X{ }; // given to me by another interface

class A{ };

class B: public A{ };
class C: public A{ };
class D: public A{ };

As I was reading of design patterns and thought I could use Factory pattern.  Is it suitable for my problem?  If so, can you please give a simplified example.....

for example, Here is a quick example of what I wanted to do......

class EmployeeInfo{  // corresponds to X
string name;
string password;
string project;
string training;
string salary;
string manager_name;
string manager_id;
int numTeamMembers;
};

class Person { };  // corresponds to A

class Employee: public Person{  // corresponds to B
string name;
string password;
string training;
};

class Manager: public Person  // corresponds to C
{
string salary;
string manager_name;
string manager_id;
int numTeamMembers;
};

Given EmployeeInfo , I want to be able to create Employee, Manager objects...

Thanks a lot.
0
Comment
Question by:ambuli
1 Comment
 
LVL 1

Accepted Solution

by:
thanesh earned 500 total points
ID: 18005839
Check out this example.
It should be easy to follow.
http://en.wikipedia.org/wiki/Abstract_factory_pattern#C.2B.2B
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now