Hello All,
Please help validate this design problem
Assume that I have several entities in my project (eg Supplier,
Customer etc).
All of them save several common properties - name, address, city,
state, zipcode etc
I thought of making a base class - BusinessEntity (with all of the
above properties)
Then, create Supplier/Customer class which derives from BusinessEntity
& have their own specialized behaviour.
Is this approach valid ?
Also, can a class be made base class solely on the basis of common
data, that it can hold ?
In my example, there is no point repeating (name, address...) in
Supplier, Customer
Hence, I think of creating BusinessEntity with all the above properties
So, is it valid to have base class with only data & no behaviour
(methods) ?
I would love to hear arguments in favour/against of the above approach
Cheers
Kalpesh 24 2018
Yes, I'd say that's valid.. and there was a good posting last week that had
an example of this (although I couldn't find it).. You could/should break it
down even further:
Have Supplier and Customer inherit from BusinessEntity. .
And BusinessEntity has several members, something like:
public PhoneEntry MainPhone = new PhoneEntry();
public PhoneEntry MainFax = new PhoneEntry();
public PhoneEntry TollFreePhone = new PhoneEntry();
public Contact MainContact = new Contact();
public Contact SalesContact = new Contact();
public Contact SupportContact = new Contact();
And PhoneEntry could have like EntryName, Number, NumberFormatted - Contact
could have Name, Address, and perhaps several "PhoneEntry " fields that hold
homephone, business, mobile, fax, etc..
So yes, it's a good thing to break up any repeating functionality into it's
own class.. HTH
"Kalpesh" <sh*********@gm ail.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com... Hello All,
Please help validate this design problem
Assume that I have several entities in my project (eg Supplier, Customer etc). All of them save several common properties - name, address, city, state, zipcode etc
I thought of making a base class - BusinessEntity (with all of the above properties) Then, create Supplier/Customer class which derives from BusinessEntity & have their own specialized behaviour.
Is this approach valid ?
Also, can a class be made base class solely on the basis of common data, that it can hold ? In my example, there is no point repeating (name, address...) in Supplier, Customer Hence, I think of creating BusinessEntity with all the above properties
So, is it valid to have base class with only data & no behaviour (methods) ? I would love to hear arguments in favour/against of the above approach
Cheers Kalpesh
"Kalpesh" <sh*********@gm ail.com> a écrit dans le message de news: 11************* ********@f14g20 00...legro ups.com...
| So, is it valid to have base class with only data & no behaviour
| (methods) ?
It is valid, sometimes, but don't make a practice of it :-)
Joanna
--
Joanna Carter [TeamB]
Consultant Software Engineer
> Also, can a class be made base class solely on the basis of common data that it can hold ?
That's not really a good way to design your class hierarchy. It's the
way that most people start out, just as most people who were learning
procedural programming split code out into a separate function only
when it was used in more than one place. After a while, though, one
tends to adopt a more sophisticated view of class hierarchy design.
Your idea of creating a BusinessEntity class isn't a bad one... I just
think that there are better reasons for doing it than that a couple of
things share data.
For me the important point here is that Supplier and Customer share
some common qualities in the real world, not just in the data that's
stored inside the computer. As a business, I can buy from (or sell to)
an (unincorporated ) individual or a corporation. I can also contract
services from an individual or a corporation. In fact, there are lots
of relationships that I can have with (external) individuals and
corporations, and in some ways they're interchangeable (in the real
world), and so it makes sense that somewhere in my class hierarchy I
would have a class that represents a generic external
person/corporation with which I'm dealing in some capacity (as a
supplier, a customer, or a contractor, or maybe some combination of
these).
So, a simple class design might be what you proposed: that there is a
BusinessEntity (some person or corporation external to my company) and
that Suppliers and Customers are BusinessEntitys .
That said, can you see how in a very large system things could quickly
become more complicated?
For example, it's fair to assume that Customers who are individuals, or
unincorporated, might have less complex information that Customers who
are corporations, so now you have IndividualCusto mer and
CorporateCustom er. That's fine... they're subclasses of Customer. But
then perhaps you have IndividualSuppl iers and CorporateSuppli ers too,
and perhaps you have a customer who is also a supplier. Now what? Do
you have a CorporateCustom er object and a CorporateSuppli er object that
really represent the same corporation? Your class hierarchy no longer
represents reality as well as it once did.
I don't have a handy class design up my sleeve for this... all I wanted
to point out is that in the end it's real-world concerns that should
dictate your class hierarchy. While "what data is stored where" and
"what data do classes have in common" may be useful questions to direct
your focus on real-world issues, it's the real world that is really the
bottom line.
For example, just because Customer and Supplier share an address and
phone number doesn't necessarily mean that they should derive from the
same base class. In this case, it seems a good idea, but SalesOffice,
an object representing some part of your own company, might not be a
good candidate for inheritance from the same base class as Customer and
Supplier. Perhaps a better solution with SalesOffice is to create a
class called PhysicalLocatio n, which in turn contains an Address object
and a ContactInfo object, which are also objects used in
BusinessEntity. Inheritance isn't the only way to share information.
Instead of inheritance in this instance you might want to consider
aggregation. For example, you could have a contact class that contains the
phone number, address, etc. And that contact class would be nestled within
your Supplier and Customer classes.
--
Tony http://geekswithblogs.net/tonyt
"Kalpesh" wrote: Hello All,
Please help validate this design problem
Assume that I have several entities in my project (eg Supplier, Customer etc). All of them save several common properties - name, address, city, state, zipcode etc
I thought of making a base class - BusinessEntity (with all of the above properties) Then, create Supplier/Customer class which derives from BusinessEntity & have their own specialized behaviour.
Is this approach valid ?
Also, can a class be made base class solely on the basis of common data, that it can hold ? In my example, there is no point repeating (name, address...) in Supplier, Customer Hence, I think of creating BusinessEntity with all the above properties
So, is it valid to have base class with only data & no behaviour (methods) ? I would love to hear arguments in favour/against of the above approach
Cheers Kalpesh
Today your base class *only* has common data. That may change tomorrow,
when you realize you need methods x y and z in your base class.
Pure data-only objects are well-expressed using structs. I suggest
instantiating your structs as private members of the base class, and
provide protected accessors to the structs' members so that the
subclasses can use them. This is sometimes known as
multiple-inheritance by delegation, and it helps keep things neat. It
also happens to be far more flexible than using multiple levels of
inheritance (base->subclass level1->subclass level 2 ...).
For example:
namespace Example
{
public class BaseClass
{
private PureData _pd;
public BaseClass() : this(int.MinVal ue, string.Empty) {}
public BaseClass(int id, string name)
{
_pd = new PureData(id, name);
}
protected string Name
{
get
{
return _pd.Name;
}
set
{
_pd.Name = value;
}
}
protected int ID
{
get
{
return _pd.ID;
}
set
{
_pd.ID = value;
}
}
}
public struct PureData
{
private int _id;
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
}
}
public int ID
{
get
{
return _id;
}
set
{
_id = value;
}
}
public PureData(int id, string name)
{
_id = id;
_name = name;
}
}
}
> Pure data-only objects are well-expressed using structs.
Sigh. Apologies for climbing back onto my well-worn soapbox, but no,
no, no... this is a C / C++ -ism and does not translate to C#.
"struct" in C# has very specific uses. It is not a "class-lite" and
should not be used like that. In particular, the example of PureData
given in your post is a _mutable_ struct: a struct with set methods. A
mutable struct is difficult to work with and should be used _only_ if
you get major payback for the pain you're going to suffer as a result
of using one.
Furthermore, structs cannot participate in inheritance, so you lose
polymorphism and all of the other goodies that come with the class
hierarchy.
IMHO, "struct" in C# is far more useful than it is in C++, where it is
nothing more than a hold-over keyword that indicates a class with no
methods, only data. In C# it allows you to create value types that can
act like the built-in value types (e.g. int, double, DateTime).
However, this also means that it shouldn't be in the same situations as
it would be used in C++.
You can see the following thread for more discussion on this point: http://groups.google.com/group/micro...7ba80c02dd3cc8
Thank you for your response. I read the thread you posted, and, though
the discussion is relevant and enlightening, it is a tad different from
the usage (delegation) I suggested. Yes, a struct is a value-type. But
does this invalidate the example? An instance of PureData is still a
private member of BaseClass, inaccessable to derived classes. Perhaps
you can show how that could create a problem for derived classes?
Kalpesh... My gut reaction is to use containment for addresses. Create
zero or
more address objects and store them in the entity, perhaps as some type
of
generic collection. The lifetime of the addresses would be dependent on
the
lifetime of the entity (composition). So Address is an object. (OOP)
The second approach would be to generate a unique ID for each entity and
create a collection of addresses which hold entity ID's. You could then
lookup
addresses related to any entity at runtime. (Relational)
A customer seems like a giant container of information. The essential
aspect of
a customer and supplier is perhaps a unique financial identity that that
can
engage in contractural relationships. So customer and supplier could
inherit
from a class that uniquely defines a financial entity. Customers can
make
purchase and suppliers can make sales. A unique financial entity could
be both a
customer and a supplier!
Regards,
Jeff
*** Sent via Developersdex http://www.developersdex.com ***
> ...does this invalidate the example?
I wasn't taking issue with the example, but with the statement that
"Pure data-only objects are well-expressed using structs," which I
directly quoted. A very, very few objects are well-expressed as
structs, and it has nothing to do with whether they are pure data-only
or not. My Fraction class, for example, has a number of methods. I
found the statement misleading and wanted to correct the impression
that "data-only object" should lead one to think of "struct". An instance of PureData is still a private member of BaseClass, inaccessable to derived classes. Perhaps
you can show how that could create a problem for derived classes?
The field is inaccessible to derived classes, true, but the struct
itself is completely public and open to be used by other classes
(derived or not) in any way they see fit. In addition, as I pointed
out, PureData is mutable, which means that people will try to do things
like this:
ArrayList pureDataList = new ArrayList();
pureDataList.Ad d(new PureData(15, "Harry");
pureDataList.Ad d(new PureData(27, "Frank");
pureDataList.Ad d(new PureData(355, "Mary");
....
PureData mary = (PureData)pureD ataList[2];
mary.Name = "Mary Smith";
and then wonder why the data in their ArrayList doesn't change. As I
mentioned in the other thread, real-world objects with identities (ID,
Name) are poor candidates for C# structs. Programmers, newbies or not,
just don't expect objects like "Customer", "Invoice", etc. to act like
values.
All of this for... what? Why not just use a class? What does a struct
buy you here that a class wouldn't? I see no advantage to using struct
here, and several disadvantages, which brings me back to the original
statement that caught my attention:
Pure data-only objects are well-expressed using structs.
No, they're not, or rather the decision to use a struct or class is
tangential to that concern. There are lots of reasons to use structs,
but that's not one of them. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: andy2O |
last post by:
Hello comp.lang.py,
Can you help me with ideas for the following (somewhat newbie) OO
design question in Python? Note, I'm using psuedo-code, not actual
Python for the examples!
Background:
-----------
I need to represent a small variety of mathematical constructs
symbolically using Python classes.
|
by: James Walters |
last post by:
Hello,
DB novice checking in here with a basic design
question. I have a table called 'nms_apps' which
stores information about all of our applications which
we have developed/maintained for our client. One
column which I would like to use is called 'used_by',
which would store information about which business
sections (Financial Management Branch, Human Resources
Branch, etc.) use a particular application. Often
|
by: Krist |
last post by:
Hi All,
I have a database design question, pls give me some help..
I want to define tables for salesman's sales target commission . The
commission could be given per EITHER sales amount of : Group of
Products OR Group of Brand.
e.g : the data example :
For one salesman_A :
product_1, product_2, product_3 etc.. => sales = $100 - $200 =>
|
by: Krist |
last post by:
Hi All,
There is some additional info I forget on this same topic I just posted.
I have a database design question, pls give me some help..
I want to define tables for salesman's sales target commission . The
commission could be given per EITHER sales amount of : Group of Products OR
Group of Brand. e.g : the data example :
For one salesman_A :
product_1, product_2, product_3 etc.. => sales = $100 - $200 =>
|
by: dixp |
last post by:
I'm new to writing multithreaded apps and I have a design question. I
have a winforms app and a class which has a method that does processing
which is time intensive. I want the user to be able to kick off the
process and continue to work in the appliaction while getting progress
updates and the ability to cancel. The method that seems easiest to me
is this:
The class exposes certain events for progress. Start, ProgressUpdate,
and...
| |
by: reageer |
last post by:
Hi all,
I have a design question:
I have a bunch of users (name, address, zip, etc.). They are assigned a
card with a specific id.
The only thing unique is this card id, or probably the combination of
all other user fields.
So it's seductive to use the card id as the primary key.
This card allows access to certain places and all access is logged.
|
by: Steve Long |
last post by:
Hello,
I have a design question that I'm hoping someone can chime in on. (I still
using VS 2003 .NET 1.1 as our company has not upgraded XP to sp2 yet. duh I
know, I know)
I have a class I wrote (CAppInit) that I use for application configuration.
It behaves similarly to Configuration.AppSettings with some extra
functionality.
This class is in an assembly (AppConfiguration) with another class. I would
now like to extend the functionality...
|
by: Brad Pears |
last post by:
Here is a simple OO design question...
I have a Contract class. The user can either save an existing contract or
they start off fresh with a blank contract, fill in the data and then save a
"new" contract.
I have a method in my contract class called "Save" which is called like
this...
dim oContract as new Contract
|
by: fjm |
last post by:
Hey everyone,
I lost my internet connection for about 5 months and finally got it back. This is one of the first places I came back to. I have to say that I had a heck of a time finding it because of the name change and facelift. :)
Anyway, good to be back. I have a question that may be more of a design question. If this post doesn't belong here, I appoligize in advance, feel free to move it.
I need to create a form that will be...
|
by: RoaringChicken |
last post by:
Hi.
Vista Ultimate
Access 2007
I'm developing an inventory database and have question on design. The database stores collection details. One item in the collection, one record. The design question is about showing related items. For example:
I have a typewriter Model 1
I have a manual for typewriter Model 1
I have a manual for typewriter Model 2 but no typewriter model 2.
What I would like is that when the record for typewriter...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |