Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question on C++Design Pattern(Urgent)

Posted on 2006-11-23
1
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
thanesh earned 2000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
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.

670 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