mercredi 30 mars 2016

What Cloneable do in java?

i am trying to study design patterns and study prototype design pattern what Cloneble do and why clone call super () and how creating duplicate object while keeping performance in mind ?

 public abstract class Shape implements Cloneable {

       private String id;
       protected String type;

       abstract void draw();

       public String getType(){
          return type;
       }

       public String getId() {
          return id;
       }

       public void setId(String id) {
          this.id = id;
       }

       public Object clone() {
          Object clone = null;

          try {
             clone = super.clone();

          } catch (CloneNotSupportedException e) {
             e.printStackTrace();
          }

          return clone;
       }
    }

Aucun commentaire:

Enregistrer un commentaire