I would implement something diferent...
each Course would have a CourseCalculator for instance... and then
diferent types of calculator could be injected...

public interface CourseCalculator {

     public Double calculate();

}

public class Course {

    private CourseCalculator calculator;

    public Course(){
      //some init code...
    }

    public void setCalculator(CourseCalculator calculator) {
            //bla bla bla...
    }

    public CourseCalculator getCalculator(){
            //bla bla bla...
    }
}


public class LimitedTimeCalculator() implements CourseCalculator{
      public LimitedTimeCalculator(Date initialDate, Date finalDate){
          //init everything...
      }

      public Double calculate(){
            Date today = new Date();
            if(inRange(today, initialDate, finalDate)){
               //   return price with discount :D
            }
            //return normal price...
      }
}

public class LotsOfCoursesCalculator implements CourseCalculator {


           public LotsOfCoursesCalculator(List<Course> courses){
               // you know what this should do...
           }


           public Double calculate(){
               if (courses.size() > min){
                       //return price with discount...
               }
               //return normal price...
           }
}


Enjoy it :D


On Aug 25, 6:27 am, "Alessandro Loche" <[email protected]>
wrote:
> You have that kind of information on entity course, haven't you? After you
> evaluate the conditions, if the result is true (that's means the conditions
> have verified) you apply the evaluation in your rule entity. A rule should
> knows hot to do if the conditions evaluation is true.
>
> And the only wrong thing is my English.
> (Smile).
>
> --------------------------------------------------
> From: "Dalla" <[email protected]>
> Sent: Tuesday, August 25, 2009 10:07 AM
> To: "Google Web Toolkit" <[email protected]>
> Subject: Re: Plain OO question
>
>
>
>
>
> > That seems like a good solution. But to me something seems to be
> > missing.
> > Let´s say I create a DiscountPriceRule, with a DateRangeCondition.
>
> > How would I apply this to the Course object? It doesn´t (and shouldn
> > ´t?) contain any information about when it was bought, how many and so
> > on.
> > It seems like I would need yet another class, somehing like an
> > CourseOrder that would contain this kind of information,
> > and that the interface DiscountPriceRule maybe should look like this?
>
> > class CourseOrder {
> >    Course course;
> >    Date OrderDate;
> >    Integer orderAmount
> > }
>
> > interface Rule {
> >    boolean evaluateConditions( CourseOrder c );
> >    Set<Condition> getConditions();
> >    void setConditions( Set<Condition> conditions );
> >    EvaluationResult apply ( CourseOrder c );
> > }
>
> > Or am I wrong again? :-)
>
> > On 25 Aug, 04:03, "Alessandro Loche" <[email protected]>
> > wrote:
> >> You should think in terms of Rules and Conditions.
>
> >> interface Rule {
> >>     boolean evaluateConditions( Course c );
> >>     Set<Condition> getConditions();
> >>     void setConditions( Set<Condition> conditions );
> >>     EvaluationResult apply ( Course c );
>
> >> }
>
> >> interface Condition {
> >>     isTrue( Course c);
>
> >> }
>
> >> Any special offer implements Rule and has one or more Conditions. A
> >> concrete
> >> rule call evaluateCondition for each conditions it has. If true, apply
> >> the
> >> result trasformation.
> >> In your case, the rule is the same, something like DiscountPriceRule. But
> >> the conditions change. One condition is about date range, another one is
> >> on
> >> totatal course amount.
>
> >> Any condition evaluates itself in a course context, and you can implement
> >> the apply() method as a Visitor. The EvaluationResult can be a new price
> >> or
> >> saving.
>
> >> Regards.
> >> --------------------------------------------------
> >> From: "Dalla" <[email protected]>
> >> Sent: Monday, August 24, 2009 10:39 PM
> >> To: "Google Web Toolkit" <[email protected]>
> >> Subject:PlainOOquestion
>
> >> > Hi all
>
> >> > This is probably a pretty basicOOquestion, 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?- Dölj citerad text -
>
> >> - Visa citerad text -
--~--~---------~--~----~------------~-------~--~----~
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