I have two classes that have some properties and behavior. One of these clusters of general behavior is manipulation in three-dimensional space. Thus, each implements an interface Transformable:
public interface Transformable {
public void position (double x, double y, double z);
public void position (Tuple3d tuple);
public void rotateDeg (double yaw, double pitch, double roll);
public void rotateRad (double yaw, double pitch, double roll);
}
public class Foo extends Apple implements Transformable {
public class Bar extends Orange implements Transformable {
Now the behavior for each method in is Transformableidentical for any implementation class, and the necessary code is essential.
Fooand Bareach of them extends various superclasses that I do not control, and Java does not have multiple inheritance, so the option is missing.
Copying and pasting a piece of code into each class that implements Transformableis contrary to all things programming.
, , :
public Foo extends Apple implements Transformable {
private TransformationHelper helper;
public final void rotate (double yaw, double pitch, double roll) {
helper.rotate(yaw, pitch, roll);
}
}
, . , .
- ?
: , Transformable. : Foo Bar . Shoe SpaceShuttle, 3D- .position(x,y,z), .