java - Design Pattern for Objects of the same type sharing various fields -
java - Design Pattern for Objects of the same type sharing various fields -
the title may sound strange, it's easier explanation:
basically have class x. there number of objects. each 2 of objects should exist 1 list can acessed both of them.
for illustration if create 4 x objects: a1, a2, b1, b2, need have 2 lists, 1 can acessed a1 , a2 , 1 acessed b1 , b2.
thanks in advance
can encapsulate 2 objects , list object? in example, objects still instances of x, , encapsulating class y:
/** * encapsulates 2 x's , list */ public class y { private x x1; private x x2; private list list; public y() { list = //..create list x1 = new x(list); x2 = new x(list); } }
have class in same bundle x, , hide x's constructor bundle level (default). if it's not default (no arguments) constructor (as case here), write private constructor.
java list object design-patterns share
Comments
Post a Comment