Design Patterns Java - Interpreter Php

1) What have we got?

We have class "Vector" which represents mathematical concept of Vector

public class Vector
{
    private double x;

    private double y;

    public Vector(double x, double y)
    {
        this.x = x;
        this.y = y;
    }

    public Vector add(Vector vector)
    {
        return new Vector(x + vector.x, y + vector.y);
    }

    public Vector multiply(double k)
    {
        return new Vector(x * k, y * k);
    }
}



this class has two coordinates: "x" and "y"

We want to do basic arithmetic operations with vectors:

- adding two vectors
- multiply vector by integer

We add two methods:
-add(Vector) - returning new vector which is sum current vector and this from argument
-multiply(int) - new vector which is the product this vector and number

2) What is our goal ?

System executes basic operations on vectors but given interface is unreadable if we want create advanced expressions


public class Client
{
    public static void main(String[] args)
    {
        Vector a = new Vector(2, 3);
        Vector b = new Vector(3, 5);
        Vector c = new Vector(1, 2);

        Vector result = a.add(b).multiply(4).add(c.multiply(2));
    }
}