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

  • SEARCH
  • Home
  • 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 6800841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:01:13+00:00 2026-05-26T19:01:13+00:00

If an object has a Single Responsibility , can the following be acceptable: public

  • 0

If an object has a Single Responsibility, can the following be acceptable:

public class Person
{
   public string Name;
   public DateTime DateOfBirth;

   private IStorageService _storageService;

   public Person(IStorageService storageService)
   {
      _storageService = storageService
   }

   public void Save()
   {
        _storageService.Persist(this);
   }
}

i.e. using a supplied collaborator (which also helps to stop the domain model being anemic).

Or should it be:

public class Person
{
   public string Name;
   public DateTime DateOfBirth;

   public Person()
   {
   }


}
public class StorageService
{
    public void Persist(Person p)
    {
    }
}
  • 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-26T19:01:14+00:00Added an answer on May 26, 2026 at 7:01 pm

    can the following be acceptable?

    class Person {
    Person(IStorageService) { } …
    void Save() { } …
    }

    This dependency doesn’t make sense.

    While it doesn’t strongly couple a Person to Storage, because it doesn’t bind them to a specific storage implementation, I argue that any such dependency makes no sense.

    Methods as verbs

    Think of methods on a class as verbs that would be carried out by that type. You’re telling an instance of that type to “do something”, with respect to its local domain.

    What does it mean when I, as a person, Save?

    • I switched my insurance provider and reduced my costs by up to 15%?
    • I’m a redemptive deity?
    • I have downloaded my soul into an automaton?

    A storage service can and should Save. People cannot Save, and should not advertise that they can.

    Trying to shoe horn it in

    SaveTo might make more sense – i.e. public void SaveTo(IStorageService storage).

    But then you’re saying a person is responsible for knowing how to save itself to storage. In my opinion, this is a violation of SRP. It is also shows a missing piece of Domain Analysis.

    The domain for a Person wouldn’t contain anything about saving, storage, etc. It would contain interactions between people, and other things at that level of the domain. The domain of data persistence is a better place for a Save method.

    If Person is in the problem domain (at that level of abstraction), then Storage is in the solution domain.

    How you should separate your logic

    You have three pieces of logic here:

    1. Person – knows about “person things”
    2. Storage – knows about the particular type of storage, and how to access it
    3. Storage of Person – knows about how a person should be committed to storage

    Following my advice above, I’d leave Person to stand on its own. However, you can either separate the logic for Storage and Storage of Person, or you can combine them.

    The approach that ORMs take is to separate all three concepts. The “Mapping” in “Object Relational Mapping” is where “Storage of Person” is encapsulated.

    This approach allows your Storage logic to focus on the potentially complicated job of reading storage configuration, connecting to storage, ensuring storage is fast, choosing alternate storage methods, etc. It also removes any dependency on your main domain’s model, so the storage code can be reused by any other domain model.

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

Sidebar

Related Questions

When an object has various formats (XML,CSV) it can be represented in, where should
My ContentValues object has string keys, and I would like to get a String[]
I get this error object has no attribute 'im_func' with this class Test(object): def
I have an single-dimensional array of PHP objects. Each object has two attributes, one
If the Single Responsibility Principle states that every object must have a single reason
i have a list of objects in a collection. Each object has a string
I have the following code and keep getting the error: AttributeError: 'NoneType' object has
If an object has a property that is a collection, should the object create
the window.open() object has some funky parameter list... is there a way to do
my onscreen object has a var rotation (in degrees). how do i fix it

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.