I have an interface which is for an object which has bounds in a 2D plane.
interface Boundable : Positionable {
/**
* Returns the [Bounds] (the [Position] and [Size]) of this [Boundable].
*/
fun bounds(): Bounds
/**
* Returns the [Size] of this [Boundable].
*/
fun size(): Size
/**
* Tells whether this [Boundable] intersects the other `boundable` or not.
*/
fun intersects(boundable: Boundable): Boolean
/**
* Tells whether `position` is within this boundable's bounds.
*/
fun containsPosition(position: Position): Boolean
/**
* Tells whether this boundable contains the other `boundable`.
* A [Boundable] contains another if the other boundable's bounds
* are within this one's. (If their bounds are the same it is considered
* a containment).
*/
fun containsBoundable(boundable: Boundable): Boolean
}
This is something like Rect in the Java SDK for example. Currently Boundable inherits from Positionable:
/**
* Represents an object which is positionable within its parent.
* Note that once positioned a [Positionable] can't be moved.
* If you want re-positionable objects @see [Movable].
*/
interface Positionable {
fun position(): Position = Position.zero()
}
Positionable is for objects which have a Position within a larger object on the same plane. This setup worked so far but now I need to have 3 versions of Boundable. One, which does not inherit from Positionable (to be used for detached or root objects), one which does and one which is Movable:
/**
* A [Movable] object is a specialized [Positionable].
* It can not only be positioned but moved as well.
*/
interface Movable : Positionable {
fun moveTo(position: Position): Boolean
fun moveBy(position: Position) = moveTo(position() + position)
fun moveRightBy(delta: Int) = moveTo(position().withRelativeX(delta))
fun moveLeftBy(delta: Int) = moveTo(position().withRelativeX(-delta))
fun moveUpBy(delta: Int) = moveTo(position().withRelativeY(-delta))
fun moveDownBy(delta: Int) = moveTo(position().withRelativeY(delta))
}
My problem is figured out a name for the variants, but I'm not satisfied with them. I came up with PositionableBoundable and MovableBoundable but they sound weird.
Are these names adequate or should I change them to something more descriptive?