How to design the accessibility problem
-
Hello All, Could any one suggest how can I design the following the problem in C++? How to provide access to a component of a Class to some third person. The constraints are 1. The third person should not be able to see the other details of the class! 2. the component should be accessible to only that particular third person! I have a solution to the problem. But I would like to know other approaches to solve the issue. Thanks in advance ~SSETH
-
Hello All, Could any one suggest how can I design the following the problem in C++? How to provide access to a component of a Class to some third person. The constraints are 1. The third person should not be able to see the other details of the class! 2. the component should be accessible to only that particular third person! I have a solution to the problem. But I would like to know other approaches to solve the issue. Thanks in advance ~SSETH
sseth21k wrote:
I have a solution to the problem. But I would like to know other approaches to solve the issue.
You might want to explain your existing solution so that a) people don't waste time on writing a suggestion for the same b) people might give you tips how to improve it
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
-
sseth21k wrote:
I have a solution to the problem. But I would like to know other approaches to solve the issue.
You might want to explain your existing solution so that a) people don't waste time on writing a suggestion for the same b) people might give you tips how to improve it
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
class AccountInterface
{
public :
virtual void CheckAccount() = 0;
};class Accountant
{
private:
AccountInterface * accountDept;
public:
Accountant():accountDept(NULL){}
void SetCompanyAccDept(AccountInterface *accDept){accountDept = accDept;}void AuditCompany() { if (accountDept) accountDept->CheckAccount(); else printf("Compnay info not set"); }
};
class company : private AccountInterface
{
private:
virtual void CheckAccount()
{
printf("Only Granted Accountant should have access to this");
}
public:
void SetAccuntant(Accountant *accountant)
{
//Based on some logic grant access
accountant->SetCompanyAccDept(this);
}
};int main (int argc, char *argv[])
{
company c1;
Accountant ac1;
c1.SetAccuntant(&ac1);
ac1.AuditCompany();}
I tried to demonstrate the idea with a company its account deptartment and an accountant. Account Details should not be public. (no Public access) The Accountant should not be able to access other details of the company ( No friend) Company is responsible for granting access permission --Private Inheritance..( is a relationship with base class but no exposed to public) Thanks, SSETH
-
class AccountInterface
{
public :
virtual void CheckAccount() = 0;
};class Accountant
{
private:
AccountInterface * accountDept;
public:
Accountant():accountDept(NULL){}
void SetCompanyAccDept(AccountInterface *accDept){accountDept = accDept;}void AuditCompany() { if (accountDept) accountDept->CheckAccount(); else printf("Compnay info not set"); }
};
class company : private AccountInterface
{
private:
virtual void CheckAccount()
{
printf("Only Granted Accountant should have access to this");
}
public:
void SetAccuntant(Accountant *accountant)
{
//Based on some logic grant access
accountant->SetCompanyAccDept(this);
}
};int main (int argc, char *argv[])
{
company c1;
Accountant ac1;
c1.SetAccuntant(&ac1);
ac1.AuditCompany();}
I tried to demonstrate the idea with a company its account deptartment and an accountant. Account Details should not be public. (no Public access) The Accountant should not be able to access other details of the company ( No friend) Company is responsible for granting access permission --Private Inheritance..( is a relationship with base class but no exposed to public) Thanks, SSETH
I'm not certain what problem you are trying to solve but that sounds far too complicated and unwieldy. The usual way to restrict things is by allocating permission levels to both users and data. That way you can grant or restrict access to individual people at run time.
-
I'm not certain what problem you are trying to solve but that sounds far too complicated and unwieldy. The usual way to restrict things is by allocating permission levels to both users and data. That way you can grant or restrict access to individual people at run time.
Thanks for respond ..I dont know if you are really getting the what exactly I am trying to target in the code.. without friend and making public accessibility I want to restrict the permission to some particular user... The way I am achieving is just one of the use case of Private Inheritance.. Could you please post here your approach(Design) in C++.. Thanks in advance..
-
Thanks for respond ..I dont know if you are really getting the what exactly I am trying to target in the code.. without friend and making public accessibility I want to restrict the permission to some particular user... The way I am achieving is just one of the use case of Private Inheritance.. Could you please post here your approach(Design) in C++.. Thanks in advance..
SSETH wrote:
Could you please post here your approach(Design) in C++..
I did in my previous message. The way you control access to different features is by taking decisions at run time, as to what facilities and data a particular user has access to. Doing it your way is nigh on impossible, and would need regular changes in the code.
-
Hello All, Could any one suggest how can I design the following the problem in C++? How to provide access to a component of a Class to some third person. The constraints are 1. The third person should not be able to see the other details of the class! 2. the component should be accessible to only that particular third person! I have a solution to the problem. But I would like to know other approaches to solve the issue. Thanks in advance ~SSETH
First off of course this is a made up problem that should never be implemented specifically in code. Parts, depending on what you mean, might be implemented in they system but not code specifically (design versus code.) But approaching it code wise.
sseth21k wrote:
1. The third person should not be able to see the other details of the class!
The implementation via class A. You have an API class that returns a proxy B. The caller uses B. B internally is implemented such that A supplies all the behavior. Specifically in C++ this means that A will NOT be in an include file. Rather it should be a source file. In ractical wise you would probably put in its own package with its own include file Code wise you could tighten this even further by delivering a binary rather than source code. Then all they could see would be the Proxy.
sseth21k wrote:
the component should be accessible to only that particular third person!
There is a credential class. It has specific data that identifies the caller. The API (above) is modified to take an instance of the credential class. The API checks the data to 'match' to the 'third person'. If it matches it returns the Proxy. If it doesn't match it returns null.