I’m writing a class that has two objects as private members, one of which is conceptually referenced by the class, and the other is conceptually owned by the class. However, the code itself gives no clue that this is the case.
public class WorklistSearchResults
{
//This is "owned" and will be disposed
private RecordSet _RecordSet = null;
private RecordSet RecordSet
{
//...
}
//This is "referenced" and won't be dispoesd
private WorkList _WorkList = null;
private WorkList WorkList
{
//...
}
//...
}
Is there a standard way to differentiate between the owned and referenced object? Are comments the only way to go here?
In languages such as C++, you may embed the owned object into the class, and point at the referenced object via a pointer.
In languages such as Java or C#, however, that solution is not usually available. As far as I know, most modern OO programming languages do not differentiate between owned and referenced objects; this is a difference that makes a lot of sense at the conceptual modelling level, but for some reason programming languages choose to ignore it.
Personally, I rely on comments and patterns to implement the differences.