logo

Crowdly

You are implementing a drawing editor that lets users draw and arrange graphical...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

You are implementing a drawing editor that lets users draw and arrange graphical elements such as lines, polygons, text, etc. The interface for graphical objects is defined by an abstract class called Shape. The editor defines a subclass of Shape for each kind of graphical object: a LineShape class for lines, a PolygonShape class for polygons, and so forth.

Classes for elementary geometric shapes like LineShape and PolygonShape are rather easy to implement, but a TextShape subclass that can display and edit text is considerably more difficult. However, you found an off-the-shelf user interface toolkit which already provides a sophisticated TextView class for displaying and editing text. Ideally we'd like to reuse TextView to implement TextShape, but the toolkit wasn't designed with Shape classes in mind. So we can't use TextView and Shape objects interchangeably.

How can existing and unrelated classes like TextView work in an application that expects classes with a different and incompatible interface? What design pattern would you use to solve this problem? Explain your decision.

More questions like this

Want instant access to all verified answers on moodle31.upei.ca?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!