Solved

Question on C++Design Pattern(Urgent)

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 62
MSVCR80.dll crash 2 141
Task manager indicates my c++ program memory consumption is growing? 12 123
Header of docx file 17 118
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

830 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