473,756 Members | 4,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building class

In the system I am working on, there are 3 credit cards: Visa, MasterCard and
AmericanExpress . On the database side I have one table: credit_card
CREATE TABLE credit_card
( credit_card_id int not null PRIMARY KEY,
credit_card_cod e varchar(30) not null,
description varchar(255) null )

Now I am building classes and i can do it in 2 ways:

* Build a class "CreditCard ".
public class CreditCard
{
private int _creditCardId;
private string _creditCardCode ;
private string _description;
}

* Build a class "CreditCard " and then build 3 classes "Visa", "MasterCard "
and "AmericanExpres s" all inherited from "CreditCard ".
public class CreditCard
{
private int _creditCardId;
private string _creditCardCode ;
private string _description;
}
public class Visa : CreditCard
{
}
public class MasterCard : CreditCard
{
}
public class AmericanExpress : CreditCard
{
}
Which way is better and why?

Thanks

Apr 30 '07 #1
4 1577
Hello Rizwan,

The second case is preferable, because u have the common data/logic for all
you classes which can be moved to the base class

Read about inheritance there http://en.wikipedia.org/wiki/Inherit...ter_science%29

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

RIn the system I am working on, there are 3 credit cards: Visa,
RMasterCard and
RAmericanExpres s. On the database side I have one table: credit_card
RCREATE TABLE credit_card
R( credit_card_id int not null PRIMARY KEY,
Rcredit_card_co de varchar(30) not null,
Rdescription varchar(255) null )
RNow I am building classes and i can do it in 2 ways:
R>
R* Build a class "CreditCard ".
Rpublic class CreditCard
R{
Rprivate int _creditCardId;
Rprivate string _creditCardCode ;
Rprivate string _description;
R}
R* Build a class "CreditCard " and then build 3 classes "Visa",
R"MasterCard "
Rand "AmericanExpres s" all inherited from "CreditCard ".
Rpublic class CreditCard
R{
Rprivate int _creditCardId;
Rprivate string _creditCardCode ;
Rprivate string _description;
R}
Rpublic class Visa : CreditCard
R{
R}
Rpublic class MasterCard : CreditCard
R{
R}
Rpublic class AmericanExpress : CreditCard
R{
R}
RWhich way is better and why?
R>
RThanks
R>
Apr 30 '07 #2
Thanks Michael.

One other person I consult with, thinks the first way is better. He is of
the view that "your classes should match one-to-one with your tables". What
do you think about that?

Hello Rizwan,

The second case is preferable, because u have the common data/logic for all
you classes which can be moved to the base class

Read about inheritance there http://en.wikipedia.org/wiki/Inherit...ter_science%29

---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog: http://spaces.live.com/laflour
Team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

RIn the system I am working on, there are 3 credit cards: Visa,
RMasterCard and
RAmericanExpres s. On the database side I have one table: credit_card
RCREATE TABLE credit_card
R( credit_card_id int not null PRIMARY KEY,
Rcredit_card_co de varchar(30) not null,
Rdescription varchar(255) null )
RNow I am building classes and i can do it in 2 ways:
R>
R* Build a class "CreditCard ".
Rpublic class CreditCard
R{
Rprivate int _creditCardId;
Rprivate string _creditCardCode ;
Rprivate string _description;
R}
R* Build a class "CreditCard " and then build 3 classes "Visa",
R"MasterCard "
Rand "AmericanExpres s" all inherited from "CreditCard ".
Rpublic class CreditCard
R{
Rprivate int _creditCardId;
Rprivate string _creditCardCode ;
Rprivate string _description;
R}
Rpublic class Visa : CreditCard
R{
R}
Rpublic class MasterCard : CreditCard
R{
R}
Rpublic class AmericanExpress : CreditCard
R{
R}
RWhich way is better and why?
R>
RThanks
R>
Apr 30 '07 #3
Rizwan <Ri****@discuss ions.microsoft. comwrote:
One other person I consult with, thinks the first way is better. He is of
the view that "your classes should match one-to-one with your tables". What
do you think about that?
What's important isn't the view, so much as the reasons behind it.
There are times when a sort of inheritance structure makes sense, and
other times when it would make life harder.

*Why* does he think that classes should match one-to-one with tables?
What advantages does he see to that approach? How applicable are they
to your situation? What advantages are there in the alternative
approach? How much difference is there (in code) between the three
different kinds of card? Could those differences be encapsulated in a
way other than straight inheritance?

In short, we haven't got enough information to say what the best course
is - you need to be looking at the pros and cons of each approach. If
there's "received wisdom" you should ask for the reasons behind it -
otherwise it's superstition rather than wisdom.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 30 '07 #4
Hi Rizwan,
I believe the person you consulted is thinking of using Reflection,
that's why he advised you to create a business Object class that match
one to one to your Database Table.
If you're going to build the system in the 3-tier architecture, that
person idea is best (i.e. creating each class for Visa, Mastercard and
Amex respectively).

But from language point of view, the second approach is more elegant
(^_^), since it's using inheritance.

Regards,
Hardono Arifanto
-----------------------
visit my blog at http://sodeve.net
On May 1, 7:06 am, Rizwan <Riz...@discuss ions.microsoft. comwrote:
Thanks Michael.

One other person I consult with, thinks the first way is better. He is of
the view that "your classes should match one-to-one with your tables". What
do you think about that?
Hello Rizwan,
The second case is preferable, because u have the common data/logic for all
you classes which can be moved to the base class
Read about inheritance therehttp://en.wikipedia.or g/wiki/Inheritance_%28 computer_scienc e%29
---
WBR, Michael Nemtsev [.NET/C# MVP].
My blog:http://spaces.live.com/laflour
Team blog:http://devkids.blogspot.com/
"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
RIn the system I am working on, there are 3 credit cards: Visa,
RMasterCard and
RAmericanExpres s. On the database side I have one table: credit_card
RCREATE TABLE credit_card
R( credit_card_id int not null PRIMARY KEY,
Rcredit_card_co de varchar(30) not null,
Rdescription varchar(255) null )
RNow I am building classes and i can do it in 2 ways:
R>
R* Build a class "CreditCard ".
Rpublic class CreditCard
R{
Rprivate int _creditCardId;
Rprivate string _creditCardCode ;
Rprivate string _description;
R}
R* Build a class "CreditCard " and then build 3 classes "Visa",
R"MasterCard "
Rand "AmericanExpres s" all inherited from "CreditCard ".
Rpublic class CreditCard
R{
Rprivate int _creditCardId;
Rprivate string _creditCardCode ;
Rprivate string _description;
R}
Rpublic class Visa : CreditCard
R{
R}
Rpublic class MasterCard : CreditCard
R{
R}
Rpublic class AmericanExpress : CreditCard
R{
R}
RWhich way is better and why?
R>
RThanks
R>

May 1 '07 #5

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

Similar topics

2
4379
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
9
2342
by: Jenta | last post by:
A World Beyond Capitalism 2005, An Annual International Multiracial Alliance Building Peace Conference Is Accepting Proposals... ...and Online Registration is now available if you plan to table and participate in the International Grassroots Exhibition: http://www.lfhniivaaaa.info/awbcgrassrootsofpeace We would greatly like some proposals from all people worldwide, especially
1
1625
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all I am using VS.NET 2003. What I am doing apart from teaching myself C# is learning my way round V.NET2003 also.
6
2783
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1) using redim arrays to add to a normal byte array (2) using an ArrayList and finally (3) using a memorystream. These three classes are listed below the test sub called "TestBuildByteArray". It was interesting that using the memorystream was...
2
1769
by: tony | last post by:
Hello!! I use VS 2003 and C# for all class library except MeltPracCommon.dll which is C++.NET The problem is that I get these warnings when building the exe file and use my class libraries. See below for a detail description. Preparing resources...
1
1448
by: Diffident | last post by:
Hello All, I have a question as to why my users are noticing error when I am building the project on the production system. Here is the problem's background. In order to build the project on the production system, I use the Visual Studio's File > Open From Web and then build the solution. Some of the build settings are as follows: Output path: bin
3
1749
by: tony | last post by:
Hello!! I use VS 2003 and C# for all class library except MeltPracCommon.dll which is C++.NET The problem is that I get these warnings when building the exe file and use my class libraries. See below for a detail description. Preparing resources...
12
2590
by: Ludwig | last post by:
Hi all, we are building our own class library framework, with stuff in it that can be used in various projects at various clients. Initially we had 4 assemblies with everything in it. Of course, when project A only needs one class, it gets everything in the assembly also; and we don't want that. Now we create an assembly for each control or main functionality, so
1
1141
by: alqui | last post by:
Hi, I'm actually trying to resolve a simple problem. I'm trying to build my Web site. The structure of the Web site looks like that : /Element /Element/App_Code /Element/Admin /Element/Modules /UserControls There are aspx pages in every folders except /UserControls where all my ascx
0
9287
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,...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9857
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,...
0
8723
agi2029
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...
1
7259
isladogs
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...
0
6542
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();...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
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 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.