53. Cloning objects

Cloning objects is not a daily task, but it is important to do it properly. Mainly, cloning objects refers to creating copies of objects. There are two main types of copies—shallow copies (copy as little as possible) and deep copies (copy everything).

Let's assume the following class:

public class Point {

private double x;
private double y;

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

// getters and setters
}

So, we have a point of type (x, y) mapped in a class. Now, let's perform some cloning.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset