I am trying to build a class library project.
The structure of the project has to be something like:
|_ Obj (class)
|_ ClassA (class)
|___ MethodA (creates object of type Objects.Obj,
populates it with data A and returns it )
|_ ClassB (class)
|___ MethodB (creates object of type Objects.Obj,
populates it with data B and returns it )
|_ ClassC (class)
|___ MethodC (creates object of type Objects.Obj,
populates it with data C and returns it )
|_ ClassD (class)
|___ MethodD (creates object of type Objects.Obj,
populates it with data D and returns it )
static FactoryF (public class. This is not under Classes directory.
| It lies at the same level as Objects & Classes folders.)
|___ MethodCreateClassObj (creates object of type objA, objB, objC or objD
of classes A, B, C, D respectively) based on parameter
passed to it and returns it. The returned object then
can be used to call Methods A, B, C or D.)
Only FactoryF should be able to create objects from classes A, B, C and D.
ie, when using this dll in another project, one should not be able to directly create objects of Class A,B,C,D, rather, one must always go through FactoryF.
FactoryF should return any ONE object ie. objA, objB, objC or objD (of classes A, B, C, D respectively) at a time.
Now, what I would like is, refer this dll in another project, say projP.
I call dll.FactoryF.MethodCreateClassObj() with an argument, and it returns one object based on the argument. say it returns objA.
then, I use objA.MethodA() to get a populated copy of Object.Obj.
But, I SHOULD NOT BE ABLE to directly create objects from projP like below:
Objects.Obj o = new Objects.Obj();
ClassA a = new ClassA(); a.MethodA();
My problem is the access modifier settings for the ClassA, ClassB... as well as for Objects.Obj and for MethodA, MethodB...
When I set Objects.Obj, Class A, B, C, D and Methods A, B, C, D to private, protected or internal,
then I cannot call Methods A, B, C, D even though I can call FactoryF and it returns an object of Class A/B/C/D successfully.
setting them public would allow direct creation of these objects...