Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strike>Who told you that? It is certainly not true in general.</p> <p>It <em>may</em> be true in some cases, where the property in question should not be modified by external parties. E.g. the interface of an immutable class surely must not contain setters.</p> <p>It is true that one should think carefully when designing interfaces, instead of blindly autogenerating getters+setters for all properties of a class. But this does not mean setters are always bad.</strike></p> <h3>Update after clarification of question</h3> <p>Your clarification changes the question completely... you could have saved yours and others' time by starting with this question right away. Although no complaints from my part - I got a lot of (undeserved) upvotes :-)</p> <p>So your problem is initializing / setting costly collection properties in a domain object. My first approach would indeed be lazy load / save, which can be implemented in a lot of different ways depending on the context.</p> <p>Your post suggests (but does not state explicitly) that the collections in question are fetched from / persisted to a DB. However, you don't mention what persistence solution you use. Neither do you explain why you don't want a "Hibernate style lazy init" - IMHO it is very efficient and easy to use in most cases. If you give us more details on these, we might be able to provide better answers.</p> <p>The splitting of interfaces you suggest may make sense if a JurassicPark object without dinosaurs and flora makes logical sense and is usable as is. Again, it is difficult to judge this without more context. You seem to be making a design decision based on an implementation detail, which is not a good idea in general.</p> <p>If you really want to go that way, you shouldn't actually need separate interfaces - just define a <code>JurassicPark</code> (abstract) base class containing the simple members plus their accessor methods, then subclass it with another class which adds the heavyweight fields.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload