I am sortof using a repository pattern to extract information from a database. I have two classes, report and reportRepository.
The trouble I have is that since reportReposity has to fill in all the details for the report object, all the members in the report have to be publicly accessible.
Is there a way so that I can ensure that only the repository class can access some of the methods of the report class and only it can set some of the properties that other classes cannot, sort of like what friend does in c++. Or is there a completely different way of handling this situation?
I am using C# in ASP.NET 2.0
This looks a bit funky but it does what your after, any property with a ‘protected’ modifier will only be accessable within that class AND any derived classes
So unless your within the repository you can’t see the Person derived class PersonBuilder which has a constructor that populates the protected properties of Person. Externally it looks like your magically populating fields without using setters or constructors.