Results 1 to 4 of 4
  1. #1
    Hercooles is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Default Design pattern for 'object mutation'

    Hello all!

    I hope someone can help me... I am looking for a design pattern or something that is suitable for changing an object's behavior massively at on specific events. For example an inchworm turning into a butterfly: the butterfly has totally different characteristics and capabilities but it is still the same creature.

    I was thinking of the State Design Pattern, but I think it does not suit this case so well, because it is primarly used for objects that just change the behavior of their methods, but I need something like 'Object1 turning into Object2 with different methods and other attributes only preserving some basic properties'.

    OK, thanks in advance!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    3,382
    Rep Power
    5

    Default Re: Design pattern for 'object mutation'

    Instead of explaining what you are looking for, explain why you need it. Then perhaps someone call offer a different approach.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Design pattern for 'object mutation'

    How about giving Object2 a constructor that takes an Object1?
    Get in the habit of using standard Java naming conventions!

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Design pattern for 'object mutation'

    How about giving Object2 a constructor that takes an Object1? Those properties that need to be preserved could be preserved via delegation.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Replies: 0
    Last Post: 11-19-2013, 05:02 PM
  2. State Design Pattern
    By blackbird in forum New To Java
    Replies: 3
    Last Post: 07-19-2011, 05:05 AM
  3. singleton design pattern
    By ziaur25@gmail.com in forum Advanced Java
    Replies: 2
    Last Post: 02-25-2011, 08:28 PM
  4. A little design (pattern?) question...
    By raindog308 in forum New To Java
    Replies: 1
    Last Post: 01-26-2011, 09:12 AM
  5. Command design pattern
    By hannes in forum AWT / Swing
    Replies: 10
    Last Post: 01-28-2010, 06:41 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •