When would you want two references to the same object?

Posted by HCBPshenanigans on Programmers See other posts from Programmers or by HCBPshenanigans
Published on 2014-08-02T18:22:02Z Indexed on 2014/08/19 10:30 UTC
Read the original article Hit count: 287

In Java specifically, but likely in other languages as well; When would it be useful to have two references to the same object?

Example:

Dog a = new Dog();
Dob b = a;

Is there a situation where this would be useful? Why would this be a preferred solution to using a whenever you want to interact with the object represented by a?

Edit: Can I just say that all of your dog related examples are Delightful!

© Programmers or respective owner

Related posts about object-oriented

Related posts about object-oriented-design