I'm not a big time OOP expert, but one way I've done something like
this is to create a containment object, call it "Schedule".  The
Schedule can have N number of Courses.  Each course has its set
price.  But the Schedule will have business logic that will determine
the final price of things based on quantity, date or whatever you
decide.  The Course class is just a dumb object that holds the value
but that's all.  I'm fairly certain this was in some class I took eons
ago (like 1981 when I was in college) but I don't remember the name.
I've used something similar to hold chains of retail store information
where my Chain is analogous to your Schedule.



On Aug 24, 2:39 pm, Dalla <[email protected]> wrote:
> Hi all
>
> This is probably a pretty basic OO question, but here goes:
> I have a simple Course class, containing a course ID, course name,
> course price etc.
>
> I´m looking for a good way to implement different types of special
> offers on these courses,
> like "buy five courses, get 10% off" or "from September 1 to September
> 15, get 5% off this course".
>
> What would be the best way to do this?
> I was thinking something like
>
> interface SpecialOffer {
>     double getSpecialOfferPrice(Course c); //Return new price
>     double getSpecialOfferSavings(Course c); //Return % saved
>
> }
>
> class BuyManyOffer implements SpecialOffer {
>
>      Integer buyManyLimit;
>
>      public LimitedTimeOffer(Date date) {
>         this. buyManyLimit = date;
>      }
>
>      public double getSpecialOfferPrice(Course c) {
>           //return something;
>      }
>      double getSpecialOfferSavings(Course c) {
>          return somethingElse;
>      }
>
> }
>
> class LimitedTimeOffer implements SpecialOffer {
>
>      Date offerStart;
>      Date offerStop;
>
>      public LimitedTimeOffer(Date dateStart, Date dateStop) {
>         this.offerStart = dateStart;
>         this.offerStop = dateStop;
>      }
>
>      public double getSpecialOfferPrice(Course c) {
>           //return something;
>      }
>      double getSpecialOfferSavings(Course c) {
>          return somethingElse;
>      }
>
> }
>
> But is this really the way to go?
> I can create different offers, the constructor allows me to dictate
> the rules for the offer to apply.
> But I don´t know how I would know if the offer applies or not at a
> given time.
>
> Somehow I need to know that the customer has bought more than x number
> of courses, or bought the course inside the time limit,
> but if I put number of courses in the interface, it wouldn´t make
> sense for the LimitedTimeOffer,
> and putting the a date in there wouldn´t make sense to the
> BuyManyOffer.
>
> Any pointers?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to