

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A series of exercises focused on object-oriented programming (oop) and design patterns. The exercises cover various topics such as reverse engineering a graph module design, implementing the decorator pattern in python, creating an ascii character iterator, and solving a travel planning problem using a graph. Each exercise includes detailed instructions and expected outcomes.
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


(a) Write down all class names, their methods and public properties; try to understand what all of them do. (b) Figure out how different classes are depending on each other. (c) Use the classes to represent the following graph:
(d) What are the weaknesses of this design? The code contains comments that raise some questions about the design, think about these. (e) How would you improve this design? How might an alternative design look like? We will come back to this later, so don’t spend too much time on it now.
(a) Define a class BeverageDecorator which is instantiated with a bev- erage object and contains two methods: get cost which adds the cost of the decorator to the total drink cost and get description which updates the description of the drink. (b) Subclassing BeverageDecorator define new ingredients: Milk and Cream. Use the ingridients to produce new drinks combinations. (c) (Optional ) Write unittests for your code and add propper docstrings.
(a) Define a new iterator class which contains two methods:
(c) Test your code using explicit calls of next method (see example in the lecture) and for loop. (d) (Optional ) Implement the same functionality using generators. (e) (Optional ) Define a new iterator which returns the same ASCII codes but in a random order. Use it to iterate over your iterable object.
(a) Think about how you can extend the original design to accomodate the new requirements. Can you come up with a better design? For example, the popular NetworkX graph library for Python uses quite a different design approach (you can look at its online documentation for inspiration). (b) Change the design as you like (refactor) and implement the new requirements. If you prefer to stick with the old design you are free to do that as well (e.g., deriving a CityNode and TransporationEdge class). Optionally update the unittests as well (unittests will be discussed later in this school, so you can skip this step for now). (c) Implement the following city graph as an example:
(d) Now find the quickest path from Berlin to Cologne, using the algo- rithm that is already provided in the graph module. (e) Provide the quickest path for alternative weight functions (hint: maybe get rid of inheritance being used to define the weight function). Use this to find the the cheapest and fastest paths between Berlin and Cologne.