Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Exercises about Design Patterns Tom Mens FWO Postdoctoral Fellow Programming Technology Lab Vrije Universiteit Brussel.

Similar presentations


Presentation on theme: "1 Exercises about Design Patterns Tom Mens FWO Postdoctoral Fellow Programming Technology Lab Vrije Universiteit Brussel."— Presentation transcript:

1 1 Exercises about Design Patterns Tom Mens FWO Postdoctoral Fellow Programming Technology Lab Vrije Universiteit Brussel

2 2 Exercise Build a simple Calculator application in Java Gradually make it more complex by adding new functionality Make use of design patterns to keep the design elegant and reusable For more information (both exercises and solutions): See CD-ROM or website

3 3 Exercise 0 MyNumber int value print() int compute() Operation String symbol int op(int,int) print() int compute() left right Plus String symbol = “+” int op(int,int) Minus String symbol = “-” int op(int,int) Divides String symbol = “div” int op(int,int) Times String symbol = “*” int op(int,int)

4 4 Exercise 1 MyNumber int value print() int compute() Operation String symbol int op(int,int) print() int compute() left right PlusMinusDividesTimes Expression print() int compute() 1 1

5 5 Exercise 2A MyNumber int value print() int compute() Operation String symbol int op(int,int) print() int compute() args PlusMinusDividesTimes Expression print() int compute() *

6 6 Exercise 2B MyNumber int value print() int compute() int countDepth() int countOps() int countNbs() Operation String symbol int op(int,int) print() int compute() int countDepth() int countOps() int countNbs() args Expression print() int compute() int countDepth() int countOps() int countNbs() *

7 7 Exercise 3A MyNumber int value print() int accept(Visitor v) {return v.visitNumber(this) } Operation String symbol int op(int,int) print() int accept(Visitor v) {return v.visitOperation(this) args Expression print() int accept(Visitor v) * Visitor int visitNumber(MyNumber n) int visitOperation(Operation o) Compute int visitNumber(MyNumber n) int visitOperation(Operation o) CountDepth int visitNumber(MyNumber n) int visitOperation(Operation o) CountOps int visitNumber(MyNumber n) int visitOperation(Operation o) CountNbs int visitNumber(MyNumber n) int visitOperation(Operation o)


Download ppt "1 Exercises about Design Patterns Tom Mens FWO Postdoctoral Fellow Programming Technology Lab Vrije Universiteit Brussel."

Similar presentations


Ads by Google