Solved

Question on C++Design Pattern(Urgent)

Posted on 2006-11-23
1
240 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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

18 Experts available now in Live!

Get 1:1 Help Now