Name: Anonymous 2012-02-18 18:14
class A has three different interfaces, based upon what type of access you have to it.
Why not factor these interfaces into three different data types? That way, more than one data type can implement the public interface, while having different implementations for the protected and or private interfaces?
The disadvantage is not having the protected/private data access enforced on the language level. You would just need to only use a A_protected pointer when you have protected Access to A,, and only use a A_private pointer when you had private access to A. So the enforcement would be in following proper naming conventions. You would also need to instantiate A as an instance of the private class:
class A {
public:
int thisIntIsPublic;
int thisMethodIsPublic(int x);
protected:
int thisIntIsProtected;
int thisMethodIsProtected(int x);
private:
int thisIntIsPrivate;
int thisMethodIsPrivate(int x);
};Why not factor these interfaces into three different data types? That way, more than one data type can implement the public interface, while having different implementations for the protected and or private interfaces?
struct A {
int thisIntIsPublic;
int thisMethodIsPublic(int x);
};
struct A_protected : public A {
int thisIntIsProtected;
int thisMethodIsProtected(int x);
};
struct A_private : public A_protected {
int thisIntIsPrivate;
int thisMethodIsPrivate(int x);
};
struct OtherAImplementation_protected : public A {
char differentMemberHere;
double differentMethodThere(int x, int y);
};
struct OtherAAImplementation_private : public OtherAImplementation_protected {
...
};The disadvantage is not having the protected/private data access enforced on the language level. You would just need to only use a A_protected pointer when you have protected Access to A,, and only use a A_private pointer when you had private access to A. So the enforcement would be in following proper naming conventions. You would also need to instantiate A as an instance of the private class:
A* instance = new A_private(...);