Use object oriented programming to solve this: Inheritance/Polymorphism Suppose we want to write an application that manages shapes that has these requirements Shapes can be circles or squares or maybe other things, but we have to be specific as to what kind of a shape we have Shapes exist in some two-dimensional space Shapes can be colored We want to compute areas and perimeters Writing just one class for all shapes would cause the code to be very messy and cause headaches when we have to add new kinds of shapes. If we write completely separate classes for circles and squares, then how can we take advantage of similarities? For example methods getColor() and setColor() should be the same for all shapes. Consider Point class having x-coordinate and y-coordinate values for Square (upper left location) and Circle (center location) classes. Square class will need “length” and Circle class will need “radius” to calculate area
Use object oriented
Inheritance/Polymorphism
Suppose we want to write an application that manages shapes that has these requirements
- Shapes can be circles or squares or maybe other things, but we have to be specific as to what kind of a shape we have
- Shapes exist in some two-dimensional space
- Shapes can be colored
- We want to compute areas and perimeters
Writing just one class for all shapes would cause the code to be very messy and cause headaches when we have to add new kinds of shapes.
If we write completely separate classes for circles and squares, then how can we take advantage of similarities? For example methods getColor() and setColor() should be the same for all shapes.
Consider Point class having x-coordinate and y-coordinate values for Square (upper left location) and Circle (center location) classes.
Square class will need “length” and Circle class will need “radius” to calculate area
Trending now
This is a popular solution!
Step by step
Solved in 8 steps with 1 images