You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Vihung Marathe <vi...@friendsprovident.co.uk> on 2007/08/21 17:52:26 UTC

Suggestion for Clone Builder in commons-lang to assist with Cloneable and clone()

Given that it is considered 'good practice' for entity objects to be
Cloneable and to have a 'proper' clone() method, can I suggest that
there be a CloneBuilder builder along the lines of HashCodeBuilder et
al.

I would expect to use it in my implementation of clone() methods as
follows

  public Object clone() throws CloneNotSupportedException {
      return CloneBuilder.reflectionClone(this);
  }

to use reflection to build a generic clone

or

  public Object clone() throws CloneNotSupportedException {
      return new CloneBuilder(this)
          .append("field1")         // note the 'field by name' usage
          .append("field2")         // rather than 'field by value'
          ...
          .append("fieldn")
          .toClone()
      ;
  }

to build a clone from specific named fields.

-- Vihung
_________________________________________________________________

This e-mail may contain confidential information and/or copyright material. This e-mail is intended for the use of the addressee only. Any unauthorised use may be unlawful.

If you receive this e-mail by mistake please advise the sender immediately by using the reply facility in your e-mail software.

The Friends Provident group of companies includes these Friends Provident plc subsidiary companies:

Friends Provident Life and Pensions Limited. Registered number 4096141.
Friends Provident Life Assurance Limited. Registered number 782698.
Friends Provident Pensions Limited. Registered number 475201.
Friends Provident Marketing Limited. Registered number 5059179.

Each of the above subsidiary companies is authorised and regulated by the Financial Services Authority.

Friends Provident Management Services Limited. Registered number 983330

The ultimate holding company is Friends Provident plc. Registered number 4113107.

All are incorporated companies limited by shares and registered in England.
Registered and Head Office: Pixham End, Dorking, Surrey RH4 1QA.

www.friendsprovident.com

_________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org