Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Question about "data hiding" OOP paradigm issue
- From: t_bigford@xxxxxxxxx (Tom Bigford)
- Subject: Question about "data hiding" OOP paradigm issue
- Date: Thu, 30 Mar 2000 13:35:11 -0800 (PST)
Hi Cedric - Thanks - I don't know if you answered Sordini's question - but you answered one of mine (unasked) - Now i see how you handle the idea of const parameters in java... Thanks - Tom --- Cedric Beust <Cedric.Beust@xxxxxxx> wrote: > > From: Sordini Emmanuele > [mailto:Sordini.Emmanuele@xxxxxxxxxxxxxx] > > > 1) When I call mc.doSomething() the state of mc is > changed, and so is > > the state of theObject. Or am I wrong? Feeding the > setter with a reference > > to mc is quite performance-effective, but clearly > breaks OOP visibility > > rules. > > 2) If, on the other hand, I passed the setter a > copy of mc, that would > > ensure respecting the rule but would generate some > memory and performance > > overhead, which is not advisable given Java's > generally poor scores. > > > > Anybody have any opinions / hints? > > It's impossible to give a general recommendation, it > really depends on the > semantics of your class. You correctly identified > the trade-offs : > > - pass by reference : efficient, but possibility for > the object to be modified > with side-effects > - pass by value (clone) : no side-effects, but > probably unnecessarily slow > > The typical way to deal with this problem is the > Immutable idiom. Break your > class in two parts, one being read-only and which > contains exclusively "const > member functions" to use C++ terminology : > > class ConstMyClass { > public Object getValue() { ...} > }; > > class MyClass extends ConstMyClass { > public setValue(Object o) { ... } > } > > Then, just pick the appropriate type in your > method's signatures. > > Does this answer your question ? > > -- > Cedric > http://beust.com/cedric > > > > --- > To unsubscribe, mail > advanced-java-unsubscribe@xxxxxxxxxxxxxxxx > To get help, mail > advanced-java-help@xxxxxxxxxxxxxxxx > > > __________________________________________________ Do You Yahoo!? Talk to your friends online with Yahoo! Messenger. http://im.yahoo.com --- To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Prev by Date: Finding the fully qualified class name from a class file.
- Next by Date: Question about "data hiding" OOP paradigm issue
- Previous by thread: Question about "data hiding" OOP paradigm issue
- Next by thread: Question about "data hiding" OOP paradigm issue
- Index(es):