2

Building a UI editor for Android and basically there are interfaces such as this:

interface Item {
    fun decorate()
    fun translate(x: Int, y: Int)
    fun rotate(rotation: Float)
    fun scale(scale: Float)
    fun select(value: Boolean)
}

also has been extended with interfaces like so:

interface Removable {
    fun remove()
}

Meaning that the View that is an Item that can be removed implements both Item (obviously) and Removable.

But in addition to these, for the Views that have unique properties, such as text properties, this has been created:

interface Updatable {
    fun update(data: Any)
}

This takes some data class that can be interpreted after type-checking to update/modify the View.

To be more clear, the implementation of Item, BasicItem will have the target View set via a setter method.

This means, a RemovableTextItem will implement Item, Removable and Updatable via delegation where one of the delegated class for Item interface would be BasicItem and for the other interfaces similar implementations would be delegated to.

The problem in this approach is the verbosity, and addition of some methods to Item now seems like a burden. Notice that inheritance here, is being avoided deliberately in practice of composition lending more to this issue.

Would you suggest shrinking all of this down to an interface Item with method update only that takes ItemProperties data class which would be interpreted by the class that implements it?

  • Last two paragraphs need to be paraphrased to make them more understandable. Maybe itemized, shorter sentences. – Tulains Córdova Aug 17 '16 at 15:41
  • if all items are removable and updatable why not have Item implement/extend Removable and Updatable? – zzzzBov Aug 17 '16 at 15:41
  • @TulainsCórdova is this clear enough now? – razzledazzle Aug 17 '16 at 16:00
  • @zzzzBov well, all items are not removable or updatable, if they were for now, what if later one method had to be removed or separated, wouldn't all others break? – razzledazzle Aug 17 '16 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.