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 6619313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:57:02+00:00 2026-05-25T20:57:02+00:00

I am trying to learn the Single Responsibility Principle (SRP) but it is being

  • 0

I am trying to learn the Single Responsibility Principle (SRP) but it is being quite difficult as I am having a huge difficult to figure out when and what I should remove from one class and where I should put/organize it.

I was googling around for some materials and code examples, but most materials I found, instead of making it easier to understand, made it hard to understand.

For example if I have a list of Users and from that List I have a
class Called Control that does lots of things like Send a greeting and
goodbye message when a user comes in/out, verify weather the user
should be able to enter or not and kick him, receive user commands and messages, etc.

From the example you don’t need much to understand I am already doing too much into one class but yet I am not clear enough on how to split and reorganize it afterwards.

If I understand the SRP, I would have a class for joining the channel, for the greeting and goodbye, a class for user verification, a class for reading the commands, right ?

But where and how would I use the kick for example ?

I have the verification class so I am sure I would have all sort of user verification in there including weather or not a user should be kicked.

So the kick function would be inside the channel join class and be called if the verification fails ?

For example:

public void UserJoin(User user)
{
    if (verify.CanJoin(user))
    {
        messages.Greeting(user);
    }
    else
    {
        this.kick(user);
    }
}

Would appreciate if you guys could lend me a hand here with easy to understand C# materials that are online and free or by showing me how I would be splitting the quoted example and if possible some sample codes, advice, etc.

  • 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-25T20:57:03+00:00Added an answer on May 25, 2026 at 8:57 pm

    Let’s start with what does Single Responsibility Principle (SRP) actually mean:

    A class should have only one reason to change.

    This effectively means every object (class) should have a single responsibility, if a class has more than one responsibility these responsibilities become coupled and cannot be executed independently, i.e. changes in one can affect or even break the other in a particular implementation.

    A definite must read for this is the source itself (pdf chapter from "Agile Software Development, Principles, Patterns, and Practices"): The Single Responsibility Principle

    Having said that, you should design your classes so they ideally only do one thing and do one thing well.

    First think about what “entities” you have, in your example I can see User and Channel and the medium between them through which they communicate (“messages"). These entities have certain relationships with each other:

    • A user has a number of channels that he has joined
    • A channel has a number of users

    This also leads naturally do the following list of functionalities:

    • A user can request to join a channel.
    • A user can send a message to a channel he has joined
    • A user can leave a channel
    • A channel can deny or allow a user’s request to join
    • A channel can kick a user
    • A channel can broadcast a message to all users in the channel
    • A channel can send a greeting message to individual users in the
      channel

    SRP is an important concept but should hardly stand by itself – equally important for your design is the Dependency Inversion Principle (DIP). To incorporate that into the design remember that your particular implementations of the User, Message and Channel entities should depend on an abstraction or interface rather than a particular concrete implementation. For this reason we start with designing interfaces not concrete classes:

    public interface ICredentials {}
    
    public interface IMessage
    {
        //properties
        string Text {get;set;}
        DateTime TimeStamp { get; set; }
        IChannel Channel { get; set; }
    }
    
    public interface IChannel
    {
        //properties
        ReadOnlyCollection<IUser> Users {get;}
        ReadOnlyCollection<IMessage> MessageHistory { get; }
    
        //abilities
        bool Add(IUser user);
        void Remove(IUser user);
        void BroadcastMessage(IMessage message);
        void UnicastMessage(IMessage message);
    }
    
    public interface IUser
    {
        string Name {get;}
        ICredentials Credentials { get; }
        bool Add(IChannel channel);
        void Remove(IChannel channel);
        void ReceiveMessage(IMessage message);
        void SendMessage(IMessage message);
    }
    

    What this list doesn’t tell us is for what reason these functionalities are executed. We are better off putting the responsibility of “why” (user management and control) in a separate entity – this way the User and Channel entities do not have to change should the “why” change. We can leverage the strategy pattern and DI here and can have any concrete implementation of IChannel depend on a IUserControl entity that gives us the "why".

    public interface IUserControl
    {
        bool ShouldUserBeKicked(IUser user, IChannel channel);
        bool MayUserJoin(IUser user, IChannel channel);
    }
    
    public class Channel : IChannel
    {
        private IUserControl _userControl;
        public Channel(IUserControl userControl) 
        {
            _userControl = userControl;
        }
    
        public bool Add(IUser user)
        {
            if (!_userControl.MayUserJoin(user, this))
                return false;
            //..
        }
        //..
    }
    

    You see that in the above design SRP is not even close to perfect, i.e. an IChannel is still dependent on the abstractions IUser and IMessage.

    In the end one should strive for a flexible, loosely coupled design but there are always tradeoffs to be made and grey areas also depending on where you expect your application to change.

    SRP taken to the extreme in my opinion leads to very flexible but also fragmented and complex code that might not be as readily understandable as simpler but somewhat more tightly coupled code.

    In fact if two responsibilities are always expected to change at the same time you arguably should not separate them into different classes as this would lead, to quote Martin, to a "smell of Needless Complexity". The same is the case for responsibilities that never change – the behavior is invariant, and there is no need to split it.

    The main idea here is that you should make a judgment call where you see responsibilities/behavior possibly change independently in the future, which behavior is co-dependent on each other and will always change at the same time ("tied at the hip") and which behavior will never change in the first place.

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

Sidebar

Related Questions

I'm trying to learn iOS development and I cant figure this out! EXAMPLE: Using
I'm trying to learn the MVVM pattern. The main problem I'm having is learning
I'm trying to learn how to use managed/unmanaged code interop, but I've hit a
I've been trying to learn to work with Models and Stores. But the proxy
I'm new to jquery but I'm trying to learn. I'm working with a drop
I'm new to jquery but I'm trying to learn. I'm working with a drop
I was trying to learn prism, but I am unable to get a very
I've been trying to learn python recently, and ran across something that I'm having
Trying to learn a bit about PDO and is going through this tutorial .
Trying to learn about php's arrays today. I have a set of arrays like

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.