Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7010371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:58:56+00:00 2026-05-27T21:58:56+00:00

Problem I’m fairly new to design patterns, and have been studying the book, Head

  • 0

Problem
I’m fairly new to design patterns, and have been studying the book, Head First Design Patterns. I need to implement a system with 3 kinds of users: Member, Moderator, Admin. A Moderator can perform everything that a Member can, plus added stuff, an Admin can perform everything that a Moderator can, plus added stuff. I have made a basic sketch of how this can be implemented with interfaces and classes; being inexperienced, I need advice from the SO community about this design – whether it’s too bloated or silly, or if it needs corrections. So please bear with me.

Possible solution
Here are the interfaces:

public interface AdminBehavior
{
    public addUser();
    public deleteUser();
}

public interface ModeratorBehavior
{
    public blockUser();
    public deletePost();
}

Behavior classes:

public class AdminBehaviors implements AdminBehavior
{
    public addUser()        {
        ...
    }
    public deleteUser()     {
        ...
    }
}

public class NoAdminBehaviors implements AdminBehavior
{
    public addUser()        {
        ...//cannot do
    }
    public deleteUser()     {
        ...//cannot do
    }
}

+ Same as above done for Moderators...classes ModeratorBehaviors and NoModeratorBehaviors

The actual User classes:

public class Member
{
    protected ModeratorBehavior moderatorBehavior;
    protected AdminBehavior adminBehavior;

    public Member()     {
        moderatorBehavior = new NoModeratorBehavior();
        adminBehavior = new NoAdminBehavior();
    }

    public login()      {
        ...
    }
    public logout()     {
        ...
    }
    public post()       {
        ...
    }
    public comment()        {
        ...
    }

    //Moderator priv'ed actions
    public blockUser()      {
        moderatorBehavior.blockUser();
    }
    public deletePost()     {
        moderatorBehavior.deletePost();
    }

    //Admin priv'ed actions
    public addUser()        {
        adminBehavior.addUser();
    }
    public deleteUser()     {
        adminBehavior.deleteUser();
    }
}

public class Moderator extends Member
{
    public Moderator()  {
        moderatorBehavior = new ModeratorBehavior();
        adminBehavior = new NoAdminBehavior();
    }
}

public class Admin extends Moderator ((or Member?))
{
    public Admin()  {
        moderatorBehavior = new ModeratorBehavior();
        adminBehavior = new AdminBehavior();
    }
}

Personally, I feel that this seems a bit over-done or confusing…better ways to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:58:57+00:00Added an answer on May 27, 2026 at 9:58 pm

    I quite like it… does seem bloated though.

    I’d probably just use inheritance. Admin extends Moderator extends Member implements UserType.

  2. UserType interface could define all your methods
  3. Member could implement all methods but with the non-behaviour
  4. Moderator could inherit from member and override the methods it requires behaviour for
  5. Admin could inherit from Moderator and override the additional methods it requires behaviour for
  6. That would be simpler I think, but less clever

  • 0
  • Reply
  • Share
    Share
    • Share on Facebook
    • Share on Twitter
    • Share on LinkedIn
    • Share on WhatsApp
    • Report

Sidebar

Related Questions

Problem: I have an address field from an Access database which has been converted
Problem I have timestamped data, which I need to search based on the timestamp
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem solved: Thanks guys, see my answer below. I have a website running in
Problem: We have a web app that calls some web services asynchronously (from the
Problem: I need an array (datamember) in a parent class A. However, depending on
Problem Description: We have a service which has applications for main mobile OS’s. We
Problem! I Have the following input (rules) from a flat file (talking about numeric
Problem PHP session in different folder. I have problem with PHP session. There are
Problem: I have 2 classes, DB class and a User class, that will work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.