Hi,
I was wondering if it is possible or advised to make getters that return collections be immutable?
So as to make peforming a collection's destructive / state altering method on the returned collection not possible or at least not alter the actual objects collecion?
It seems from my testing if I create a get property to return an object attribute that is a collection, I am able to use the collection's methods to alter the state of the collection.
Should I be using a clone method in my getter code so I am passing back a clone and not the actual attribute collection?
Should I also then provide class methods for perfoming operations such as clearing the objects collection internally?
I have been speaking with the Catalyst community and one of the things they picked up on was my use of calling methods on object 'C' from object 'A'. Me.ObjectB.ObjectC.Method() or as they write it
I assume this principle is universal regardless of programming language?
Your imput is appreciated.
Regards,
1DMF.
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Dance Music Downloads
I was wondering if it is possible or advised to make getters that return collections be immutable?
So as to make peforming a collection's destructive / state altering method on the returned collection not possible or at least not alter the actual objects collecion?
It seems from my testing if I create a get property to return an object attribute that is a collection, I am able to use the collection's methods to alter the state of the collection.
Should I be using a clone method in my getter code so I am passing back a clone and not the actual attribute collection?
Should I also then provide class methods for perfoming operations such as clearing the objects collection internally?
I have been speaking with the Catalyst community and one of the things they picked up on was my use of calling methods on object 'C' from object 'A'. Me.ObjectB.ObjectC.Method() or as they write it
if you have code in A which says $self->b->c->some_method then A is breaking the law of demeter, as it knows that B is implemented in terms of C.
I assume this principle is universal regardless of programming language?
Your imput is appreciated.
Regards,
1DMF.
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Dance Music Downloads