Skip to content
Snippets Groups Projects
Commit a01bdd58 authored by Dao's avatar Dao
Browse files

feat(part3): add answer for Exercise 3.

parent 2eb94da3
No related branches found
No related tags found
No related merge requests found
## Answer:
For the requirement:
> - The program could potentially support more shapes in the future than the three currently listed (triangle, quadrilateral, circle).
> - More calculable operations should be supported than currently (area and boundaries).
> - One generally desired feature is that the program can better utilize the support offered by the compiler and the language types for describing the operational logic, given that a compiled language is being used (Java, but also applicable to other languages).
- Currently, we have `area` and `boundaries` operations in all shapes (triangle, quadrilateral, circle) and the formulas of the operations are based on the shape type (e.g: the area of the circle is different from the area of the triangle).
->
- We have these classes: `Triangle`, `Quadrilateral` and `Circle`. All of them implement an interface: `ShapeInterface` with 2 methods for now: `boundaries()` and `area()`.
- Later, if we have another shape, we can create a new class that implements the `ShapeInterface`. If we have more operations, we should add the new operations to the `ShapeInterface` and implement them in all shape classes.
- With this way, the program can better utilize the support offered by the compiler and the language types for describing the operational logic.
- The expected result is a summary of all area and boundaries of all patterns, it means there is something that has same operations (`area()`, `boundaries()`) with `Circle`, `Triangle`, `Quadrilateral` and it is a composite of them
->
- We have a `CompositeShape` class that also implements the `ShapeInterface`.
Next requirement:
> - The number of shapes could also vary from zero to an arbitrarily large number.
-> It means the `CompositeShape` class may contain multiple shapes.
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment