473,385 Members | 1,356 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,385 software developers and data experts.

Proper class design question please

I have a Customer table in the database that relates to a CustomerType table
(I have several other table combinations in the database like Document and
DocumentType).

As far as I can tell, I have several ways of defining the Customer class:
1) Use inheritance, where I will have an abstract base class CustomerBase
that other, concrete customer class can subclass, i.e. Private, Company etc.
2) Use composition, so the Customer class would contain a CustomerType
class, exposed as a property.
3) Similar to the second option, but instead of a class, use enum, exposed
too as a property (perhaps instead of an enum, the class would use an int,
just like the Customer table in the db).

What is the right way of defining these type of classes please? I want to be
able
to show instances of them in a grid, or some other type of display, being
able to filter out types that don't belong to the criteria, for example if
the user is looking at the customer list, he would be able to filter rows, by
using a ComboBox for instance.

I'm new to object oriented design and classes, so I'm kinda lost in
situations like these. Any help would be greatly appreciated.

Thank you very much,
Ben

Jan 14 '07 #1
2 1198
If u only have a Customer and CustomerType use a Customer Class and an
Enum to specify the type of the customer.

If your customer types contain some special properties like
CustomerA.CustomerAProperty and CustomerB.CustomerBProperty u should
use composition to add these special properties to your customer class.

hope this helps

Jan 15 '07 #2
Hello Ben,

"Ben" <Be*@discussions.microsoft.comwrote in message
news:42**********************************@microsof t.com...
>I have a Customer table in the database that relates to a CustomerType
table
(I have several other table combinations in the database like Document and
DocumentType).

As far as I can tell, I have several ways of defining the Customer class:
1) Use inheritance, where I will have an abstract base class CustomerBase
that other, concrete customer class can subclass, i.e. Private, Company
etc.
2) Use composition, so the Customer class would contain a CustomerType
class, exposed as a property.
3) Similar to the second option, but instead of a class, use enum, exposed
too as a property (perhaps instead of an enum, the class would use an int,
just like the Customer table in the db).

What is the right way of defining these type of classes please? I want to
be
able
to show instances of them in a grid, or some other type of display, being
able to filter out types that don't belong to the criteria, for example if
the user is looking at the customer list, he would be able to filter rows,
by
using a ComboBox for instance.

Welcome to the Object Relational Impedence Mismatch.

In Relational design, you are trying to isolate data duplication through
normalization. Therefore, in your relational model, you create
relationships between independent variables. In this case, Customer and
CustomerType. This reduces duplication and allows for very efficient query
processes.

But in OO development, you are not trying to make your data efficient (per
se). You are trying to encapsulate things that vary while exposing
commonality. It's a different mindset.

For CRUD-style applications, you can bring the data-oriented thinking
straight up to the surface. You can query into your app a memory-copy of
the entire CustomerType table (in a dataset). Then, when you retrieve a
Customer row, you can look up the related data from the dataset of
CustomerType. You can also use this dataset to prepopulate drop-downs or
validate data entry.

For applications that encode business rules or manage workflow or need to
drive functionality based on the customer type, you have a different
problem. In that case, the data values are merely shadows of the business
rules you are trying to implement. In that case, look to design patterns to
help you out.

For example, if the selection of a particular customer type infers that a
specific taxation method must be used, then a Strategy pattern may need to
be used, along with a factory method, to encapsulate the logic to decide
what strategy to use. If you need the behavior of the Customer object
itself to change based on the selection of Customer Type, then the State
pattern may be more helpful. (For example, if a 'High Value Corporate'
customer has the ability to apply for an extention of credit wherein a
'Retail customer' does not... the ApplyForCredit method would behave
entirely differently).

I hope this helps,

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Jan 15 '07 #3

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

Similar topics

7
by: BCC | last post by:
Hi, I have a class with several member variables that should be initialized according to user input before an object is instantiated. Using a static variable is required here. But, I would...
0
by: BlueMonkMN | last post by:
I've been trying to think of the right way to design relationships between objects with different desired lifetimes that raise events. If an event source is a relatively permanent object and the...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
3
by: Peter | last post by:
Hi, I have a question about good class design .... In my class I have some properties related to large amount of data. What is the best strategy, to include a reference to those data (and...
1
by: Stefan Richter | last post by:
Hi, I have to write a little program, to enter and retrieve data from a database. The most important aspect is that the code is easy to understand, clear and organized, and easy to modifiy or...
5
by: Dave Johnson | last post by:
Working on Asp.net with access database backend,a serious Question in the Class design phase, for accessing the database; Which is Better to make a Connection Class that handles all the ADO...
2
by: John | last post by:
Hi there, I am writing a simple program that will connect to database. Database has 2 tables, let's call them father and child. This is one to many relationship. I would like to create...
1
by: mattmao | last post by:
I am brand new to C#.NET so here is my trial on this lab exercise: using System; using System.Collections.Generic; using System.Text; using System.Collections; namespace lab02exec { ...
8
by: =?Utf-8?B?QmVu?= | last post by:
Hi, I have a couple of questions about the proper design of classes. I'll use a simple Customer class for my question. 1) Lets say that I have this Customer class like I said, and I want to...
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
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.