473,378 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Domain Model/Object Design question

I'm trying to modem a relationship with classes and I'm having trouble
finding the correct design pattern. Maybe someone with more experience
knows which pattern(s) I'm looking for. Here's an explanation of what I
have and in which direction I'm thinking:

CLASS DESIGN
=============
1. Generic class "Company" contains general company information (name,
address, reference person, phone, etc...)

2. A class "Manufacturer", which is another type of company with a
particular function, namely that they manufacture products. It has
manufacturer-specific properties

3. A class "Publisher", which is a type of company with a particular
function, namely that they publish books. They could be considered a
"Manufacturer" as well, since they create books, but they do more than
just create them... they also publish them, and that's an action that
doesn"t apply to manufacturers in general. This class also has
publisher-specific properties.

4. A class "Distributor", which is yet another type of company with a
particular function, namely that they distribute products. They don't
necessarily create products, but only distribute them.
This class has distributor-specific properties.

5. A class CompanyFactory, which is responsible for company-related
actions such as CRUD actions, listing methods, etc...
REQUIREMENTS
=============
1. A company can be a manufacturer, publisher or distributor, or any
combination of these 3. It's possible for a company to have just 1 role
or have all 3.

2. In the UI I need to be able to display lists of companies by type
(e.g. a list of all manufacturers, a list of all distributors)

3. In code, I would like to see something like
//Create a new company that is both a publisher and a distributor
Company newCompany = new Company();
newCompany.Name = "Henle Verlag";
newCompany.IsPublisher = true;
newCompany.IsDistributor = true;

//This code returns the same object
Publisher publisher = CompanyFactory.GetPublisher("Henle Verlag");
Distributor distributor = CompanyFactory.GetDistributor("Henle
Verlag");

4. In the above code, could I somehow ensure that Company has the
IsPublisher, IsDistributor and IsManufacturer fields (probably related
to the corresponding DB field in table Companies), but that the derived
classes don't show this field (they don't need to because the class, by
its name, already knows what type it is)?

5. In the future, we may need additonal types of companies, such as
"sponsor".

DESIGN IDEAS
============
Thus far I came up with the idea that Company is a base class from
which Publisher, Distributor and Manufacturer are derived (inherited).
The problem with that is that a Publisher can also be a Distributor,
but a Publisher object cannot be changed into a Distributor object once
it's created as a Publisher object, or can it in some way? On the other
hand, if I instantiate the object simply as Company, then I don't have
the type-specific properties...
Related to point 4 of the Requirements, I have a visibility issue:
If I want CompanyFactory.GetPublishers to return a list of all
publishers, then I need to have access to the Company.IsPublisher
property, so it must be public. On the other hand, if I don't want to
see that property in the inherited Publisher class, it shouldn't be in
the Company class... what to do?

Jan 2 '07 #1
3 1689

I would make four classes:

Manufacturer, Publisher, Distributor which each have information
specific to their scope and there is no inheritance relationship
between these classes--they're totally independent.

Then have one Company class which has the generic info all companies
have and then an optional instance of Manufacturer, Publisher,
Distributor. So each Company instance can be a Manufacturer,
Publisher, and/or Distributor based on it's composed classes. You
could create helper classes fo IsXXX and whatever else is needed to
make this scenario quicker to program.

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking Mid/Sr. .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On 2 Jan 2007 09:25:00 -0800, "Froefel" <ha************@gmail.com>
wrote:
>I'm trying to modem a relationship with classes and I'm having trouble
finding the correct design pattern. Maybe someone with more experience
knows which pattern(s) I'm looking for. Here's an explanation of what I
have and in which direction I'm thinking:

CLASS DESIGN
=============
1. Generic class "Company" contains general company information (name,
address, reference person, phone, etc...)

2. A class "Manufacturer", which is another type of company with a
particular function, namely that they manufacture products. It has
manufacturer-specific properties

3. A class "Publisher", which is a type of company with a particular
function, namely that they publish books. They could be considered a
"Manufacturer" as well, since they create books, but they do more than
just create them... they also publish them, and that's an action that
doesn"t apply to manufacturers in general. This class also has
publisher-specific properties.

4. A class "Distributor", which is yet another type of company with a
particular function, namely that they distribute products. They don't
necessarily create products, but only distribute them.
This class has distributor-specific properties.

5. A class CompanyFactory, which is responsible for company-related
actions such as CRUD actions, listing methods, etc...

Jan 2 '07 #2
"Froefel" <ha************@gmail.coma écrit dans le message de news:
11*********************@k21g2000cwa.googlegroups.c om...

| DESIGN IDEAS
| ============
| Thus far I came up with the idea that Company is a base class from
| which Publisher, Distributor and Manufacturer are derived (inherited).
| The problem with that is that a Publisher can also be a Distributor,
| but a Publisher object cannot be changed into a Distributor object once
| it's created as a Publisher object, or can it in some way? On the other
| hand, if I instantiate the object simply as Company, then I don't have
| the type-specific properties...
| Related to point 4 of the Requirements, I have a visibility issue:
| If I want CompanyFactory.GetPublishers to return a list of all
| publishers, then I need to have access to the Company.IsPublisher
| property, so it must be public. On the other hand, if I don't want to
| see that property in the inherited Publisher class, it shouldn't be in
| the Company class... what to do?

This topic was answered only two weeks ago in this same group. My guess is
that this is a homework assignment ?

Nevertheless, forget deriving from Company, look at the idea of having a
Role base class, from which Publisher, Distributor and Manufacturer derive.
Then have a Roles property in the Company class.

This way a Company can optionally adopt any one or more Roles without
polluting the Company class with irrelevant details. You do not need a
Comapny.IsPublisher property, all the factory has to do is scan the
Companies, checking which ones have a Publisher object in the Roles list
property.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 2 '07 #3
I second the role based idea, this is the direction i would go in. Its
possible that a company could be both a Publisher & a Disributor, or as
you mentioned, a Publisher and a Manufacturer. So any given company
would have zero to many possible roles such as Publisher, Distributor,
Manufacturer. This is the only way you can change the roles at run
time. You can't change inheritance at runtime.

So a Company might have a Roles property, which is a collection of the
roles mentioned above. Also, each role (manuf., publisher, etc) may
need a reference back to their "parent" company, so you should do that
as well.

-Fregas

Joanna Carter [TeamB] wrote:
"Froefel" <ha************@gmail.coma écrit dans le message de news:
11*********************@k21g2000cwa.googlegroups.c om...

| DESIGN IDEAS
| ============
| Thus far I came up with the idea that Company is a base class from
| which Publisher, Distributor and Manufacturer are derived (inherited).
| The problem with that is that a Publisher can also be a Distributor,
| but a Publisher object cannot be changed into a Distributor object once
| it's created as a Publisher object, or can it in some way? On the other
| hand, if I instantiate the object simply as Company, then I don't have
| the type-specific properties...
| Related to point 4 of the Requirements, I have a visibility issue:
| If I want CompanyFactory.GetPublishers to return a list of all
| publishers, then I need to have access to the Company.IsPublisher
| property, so it must be public. On the other hand, if I don't want to
| see that property in the inherited Publisher class, it shouldn't be in
| the Company class... what to do?

This topic was answered only two weeks ago in this same group. My guess is
that this is a homework assignment ?

Nevertheless, forget deriving from Company, look at the idea of having a
Role base class, from which Publisher, Distributor and Manufacturer derive.
Then have a Roles property in the Company class.

This way a Company can optionally adopt any one or more Roles without
polluting the Company class with irrelevant details. You do not need a
Comapny.IsPublisher property, all the factory has to do is scan the
Companies, checking which ones have a Publisher object in the Roles list
property.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
2
by: Julia | last post by:
Hi, I have asked this before,and I didn't get answer, I guess I didn't properly explain self I have a domain model in which the lower component-Channel- in the hierarchy can be replaced at...
0
by: AMDIRT | last post by:
I have a few questions about IssueVision (from WindowsForms) concerning its scalability and performance. Rather, if I were to implement techniques described here into another application, how...
0
by: Steven Kelly | last post by:
For those going to XP 2005 (Sheffield, UK, June 18-23) and interested in modeling, the following workshop may be of interest: Agile Development with Domain Specific Languages Scaling up Agile -...
3
by: aa7im | last post by:
I am trying to design a good domain model for a system I am working on but I am having a hard time trying to figure out how to deal with relations and transaction... For example if I create an...
3
by: cmay | last post by:
I am trying to build more applications using a more OO approach, with more seperation of business and presentation logic. One problem I am running into involves the design philosophy behind...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
6
by: Bill44077 | last post by:
Hi, I am new to the MVP pattern and one of the main reasons that we are going this route is because we are doing Scrum with 30 day sprints - so we have a continually morphing design. We are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.