I'm confused about this! Why is GetIdValue() defined as protected instead of public?
Isn't its purpose to allow the object to identify itself?
It seems like a catch-22 sort of thing:
"My job is to identify myself, but you aren't allowed to ask me."
ajj3085:I think it might be important actually. The value used by GetIdValue is only there to ensure the object compares correctly, and to ensure uniquenes if its in a collection. Its not something that necessarly represents a database id; it could be a temporary construct.
If GetIdValue were public, you would have a harder time changing exactly how you determine if an object is unique or not down the line. With the protected approach, you could do that without having to worry about breaking any clients.
Are you sure about that? It seems exactly backwards to me! :)
GetIdValue returns an object that uniquely identifies the business object.
If GetIdValue were public, one could take a given instantiated business object and ask if it were equal to another instantiated business object - and the code would always work.
You could argue that if you had some field values and wanted to compare, you would have to know how to cast the returned object. But you need to know what fields to use anyway, so how does that make it better?
Mind you, I'm not saying you are wrong! Just that I don't understand why you are right! :)
david.wendelken:Are you sure about that? It seems exactly backwards to me! :)
david.wendelken:GetIdValue returns an object that uniquely identifies the business object.If GetIdValue were public, one could take a given instantiated business object and ask if it were equal to another instantiated business object - and the code would always work.
But we already can do that. Use the Equals method of the business object. Rocky provides that functionality in Csla already for us.
So you're talking about two BOs which are of different types then? Usually different types means right away they won't be equal. In the other cases, I would think in your business layer you would create an object which implements IEqualityComparer, and that would be used to compare your differing objects. If two BOs are equal sounds like a business rule.. so it should be there.david.wendelken:You could argue that if you had some field values and wanted to compare, you would have to know how to cast the returned object. But you need to know what fields to use anyway, so how does that make it better?
Copyright (c) Marimer LLC