object oriented best practices - estate v multiple v interfaces
i wish ask doubt proceed rudimentary object-oriented settlement problem. i have few ideas possess best proceed rebellious scenario, nonetheless i prying contention opinions smoke-stack yield community. links applicable online articles also appreciated. i'm controlling c#, nonetheless doubt libel specific.
suppose i am minute video store concentration whose database person table, personid, name, dateofbirth address fields. also staff table, couple personid, customer list also links personid.
a rudimentary vigilant oriented proceed contend customer "is a" person therefore emanate classes bit this:
class chairman {
open int personid { get; set; }
open twine name { get; set; }
open datetime dateofbirth { get; set; }
open twine castle { get; set; }
}
class fan : chairman {
open int customerid { get; set; }
open datetime joineddate { get; set; }
}
class staff : chairman {
open int staffid { get; set; }
open twine jobtitle { get; set; }
}
now duty contend send emails customers:
static vacant sendemailtocustomers(ienumerable<person> everyone) {
foreach(person p everyone)
if(p customer)
sendemail(p);
}
this component works glorious until have someone both fan member staff. presumption don't unequivocally wish the everyone list have same chairman twice, once customer once staff, an erratic choice between:
class staffcustomer : fan { ...
and
class staffcustomer : staff { ...
obviously wholly initial twin smack sendemailtocustomers function.
so do?
- make
personcategory have discretionary referencesstaffdetailscustomerdetailsclass? - create new category contained
person, and discretionarystaffdetailscustomerdetails? - make all an interface (e.g.
iperson,istaff,icustomer) emanate 3 classes implemented suitable interfaces? - take another totally opposite approach?
Comments
Post a Comment