oop - should I use aggregation in this case? -


in case have class called payment superclass of class named card, how can join class verifies if card valid. uml diagram this:

payment<---------card 

i have thought of 2 ways of doing this, know 1 correct one:

1) model association check if credit card valid, not join paymentcard:

card_list---1--------------1*---<>card 

so within class card call like:

class paymentcard extends payment {      public authorized()        ---abstract method      {           if card.verified(card_number) return true;     ---here call card class           else return false;      } } 

2) have read can use aggregation, little dubious how use it:

class paymentcard extends payment {           card creditcard                  //aggregation           public authorized()           {                creditcard=new card(numbercard)                if creditcard.verified() return true;                else return false;           }  } 

which 1 of 2 forms better? me, first 1 looks query external class can database, while second 1 not pretty sure it

any comment?

one day want have other payment methods.

imo, payment has payment_method can bycard, by..., so:

class payment {     protected paymentmethodoption; }  abstract class paymentmethod {     public abstract bool authorized(); }  class paymentbycreditcard : paymentmethod {     public override bool authorized() { return card.verified(card_number); } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -