0

I need an advice. I'm developing an program for managing Student's Projects in college. (I student myself, it my project for 2nd year). Using c# .NET 4, WINFORMS.

I have different users with different permissions. I don't want to use heavy-weight solutions like using DB, adding GROUPS, ...

permissions

I want an very simple solution for this, and, I NEED to use at least one of 23 programming patterns for this.

I learned about basic patterns like Abstract Factory, Strategy, Singleton and others... but I can't choose the right one.

If I use basic inheritance, so I'll need to override some methods in childs, for "to do nothing", because they inherit all method of the parent...

Any ideas? The main goal is to use an design pattern.

Sorry for poor English :)


Comment was too long, so I'll write here...

I know that I need use patterns only where I need it. But, go tell it to my teacher =))

He wants me use 3 patterns in my programm. I used Singleton for connection to MySQL, for example.

So I need to use 2 more patterns.

How it works. Somebody enters to system. I create "pointer" in static class Auth to logged in user:

static class Auth
{
   public static CommonUser _currentUser;

   public static CommonUser getUser()
   {
      return Auth._currentUser;
   }
}

For example if teacher are logged in so I do:

Auth._currentUser = new Teacher(id, name, blablba, blabla, blabla);

If he wants to add, say, new Project, he clicks on button ADD PROJECT, form Add Project is called, he fill all inputs, clicks ADD and I must call for:

Auth._currentUser.addProject(projectId, projectTitle, ....);

If Admin logged in to system, so for adding new Project, I do:

Auth._currentUser = new Admin(id, name, blablba, blabla, blabla);

And then called the same method.

Auth._currentUser.addProject(projectId, projectTitle, ....);

But here metod addProject is the same, so I must use inheritance.

But if Seretary logged in I do:

Auth._currentUser = new Seretary(id, name, blablba, blabla, blabla);

And Secretary must haven't permissions to do:

Auth._currentUser.addProject(projectId, projectTitle, ....);

So need I override addProject method in Secretary Class and to do it empty, or call for an MessageBox?

Something like that... so, he want me to use an pattern here :-/ Say.... if I'll need to add somebody else with different permissions, so I will not need to make changes in all my programm...

Some pictures for example (sorry for hebrew):

Login form

Project adding

4
  • 1
    Whats wrong with having a ROLES table in your database and checking the role of the user to validate they can preform an action?
    – Evo510
    May 7, 2013 at 16:52
  • 2
    “I NEED to use [a] programming pattern” – That’s a terrible task… Make sure you tell them that. You should use patterns where it makes sense to use them (and often, you use them automatically without having to know them), not to build a problem around them…
    – poke
    May 7, 2013 at 16:55
  • I don't think there is a pattern for a 'simple' permission system. There maybe a framework, but still, you should only use a pattern when it actually makes sense to use it. EG A single web page that won't grow past a single page, MVC probably is more trouble that it is worth.
    – Justin
    May 7, 2013 at 17:17
  • Could you tell us a bit more about how your users are made and how they interact with the system (e.g. how is “Add research” implemented? Is it in the secretary user? Is there a research repository?)
    – poke
    May 7, 2013 at 17:19

1 Answer 1

0

One way to do this would be to use the Command (or Action) pattern where each operation (e.g. Add Research) is encapsulated in an object. This allows for checking permissions in a central place before the action is actually executed.

The actual permission check is usually done by mapping users to roles/groups and defining a set of allowed operations for each group. This could be implemented using Microsofts Authorization Manager, or a simple Roles-Table in the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.