Re: Building class

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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/Inheritance_%28computer_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

R> In the system I am working on, there are 3 credit cards: Visa,
R> MasterCard and
R> AmericanExpress. On the database side I have one table: credit_card
R> CREATE TABLE credit_card
R> ( credit_card_id int not null PRIMARY KEY,
R> credit_card_code varchar(30) not null,
R> description varchar(255) null )
R> Now I am building classes and i can do it in 2 ways:
R> R> * Build a class "CreditCard".
R> public class CreditCard
R> {
R> private int _creditCardId;
R> private string _creditCardCode;
R> private string _description;
R> }
R> * Build a class "CreditCard" and then build 3 classes "Visa",
R> "MasterCard"
R> and "AmericanExpress" all inherited from "CreditCard".
R> public class CreditCard
R> {
R> private int _creditCardId;
R> private string _creditCardCode;
R> private string _description;
R> }
R> public class Visa : CreditCard
R> {
R> }
R> public class MasterCard : CreditCard
R> {
R> }
R> public class AmericanExpress : CreditCard
R> {
R> }
R> Which way is better and why?
R> R> Thanks
R>


.



Relevant Pages

  • Re: Building class
    ... R> public class CreditCard ... R> private int _creditCardId; ... R> private string _creditCardCode; ...
    (microsoft.public.dotnet.general)
  • Re: Building class
    ... person idea is best (i.e. creating each class for Visa, Mastercard and ... R> public class CreditCard ... R> private string _creditCardCode; ...
    (microsoft.public.dotnet.general)
  • Re: data transporting questions
    ... > public class Location implements java.io.Serializable { ... > private int locationId; ... > private String locationName; ... > public class Employee implements java.io.Serializable { ...
    (comp.lang.java.programmer)
  • Re: hibernate question ?
    ... public class Address { ... private int id; ... private String street; ... Student emp = new Student; ...
    (comp.lang.java.programmer)
  • Re: hibernate question ?
    ... public class Address { ... private int id; ... private String street; ... Student emp = new Student; ...
    (comp.lang.java.programmer)