user7739271
user7739271

Reputation:

How to name a base class name right?

I have a model like this image:

1

Then, I have created some classes based on the model:

public abstract class AccountManager
{
    public void LockAccount(string userId)
    {

    }
}

public class AdministratorTool : AccountManager
{
    public void DeleteAccount(string userId)
    {

    }

    public void UnlockAccount(string userId)
    {

    }
}

public class ModeratorTool : AccountManager
{

}

public class MemberTool : AccountManager
{

}

My question: What is the name that I should change with AccountManager?

I want to do that because Account manager means: provides some methods to do with an account.

Because DeleteAccount and LockAccount do exactly the same (working with an account), so, putting DeleteAccount and LockAccount outside AccountManager will make changes.

If I still want to keep the two methods inside AdministratorTool, I need to change the name of AccountManager.

So, can you give me a name for that?

And...my sub question is: may you give me some tips to name a class? There are several questions about how to create a base/derived class but naming a class name.

Thank you!

p/s: this question comes from I'm not good at English :((

Upvotes: 0

Views: 707

Answers (1)

Zohar Peled
Zohar Peled

Reputation: 82474

Privileges usually tend to accumulate as you go higher in the hierarchy - and you can see the same thing in the real world - A CTO is a specific type of a manager, and a manager is a specific type of employee. Being a CTO does not deny you any of the privileges you had when you was only a low-rank employee. For example - no one would tell the CTO that they can't use the companie's bathroom - as this is a privilege shared by all employees.

So unless a member can do things that a moderator can't or a moderator can do things that an administrator can't , I wouldn't even bother with an abstract base class.
I would simply have the Member class, let the Moderator class inherit from Member and extend it with moderator and above abilities, and let the Administrator class inherit from Moderator and extend it with administrator abilities:

public class Member
{
     public void LockMyAcount() {/* implementation */}
}

public class Moderator : Member
{
     public void LockAccount(string userId) {/* implementation */}
}

public class Administrator : Moderator 
{
     public void DeleteAccount(string userId) {/* implementation */}
     public void UnlockAccount(string userId) {/* implementation */}
}

Upvotes: 1

Related Questions