All Questions
Tagged with object-oriented-design single-responsibility
35
questions
0
votes
1
answer
78
views
Shopping Cart Design with SRP: Handling Cart Creation and Update Separately
I'm working on designing a shopping cart system that respects the single responsibility principle. However, I'm facing a challenge when it comes to handling cart creation and updating separately.
...
31
votes
10
answers
6k
views
Does logging inside a class violate the SRP?
I wrote a class that takes a Logger class as one of its arguments:
class QueryHandler:
def __init__(self, query: Query, logger: Logger) -> None:
self.query = query
self.logger =...
1
vote
3
answers
470
views
Too much parameter in a class' constructor, when trying to conserve the dependency injection principle [duplicate]
I am developing a simulator of a bank software system, where each operation (deposit, withdraw, transfer, ...) is just a string.
I have 5 main classes :
Bank where bank accounts are stored.
...
8
votes
3
answers
523
views
Breaking up a class with too many responsibilities
I'm looking for advice on my specific problem, how to break up a class, Basket, that has too many responsibilities.
Currently, it does three things:
Keeps track of the products in the basket: ...
1
vote
4
answers
384
views
Is there multiple definitions for responsibility of class?
In the book UML 2 and the Unified Process from Arlow and Neustadt has been told:
Analysis classes should have 3 to 5 responsibilities
But as you know we have the SRP that tells us something else!!
...
4
votes
3
answers
588
views
What to do when interfaces force me into violating the single-responsibility principle?
(The code I'd have to post is huge, I'll resume to just function names)
I'm currently faced with the following issue on my project: I have a "each module from this framework can have a small view ...
3
votes
1
answer
296
views
User class: How do I handle different user "subjects" and still keep my single responsability principal?
I have a User class, this class handles things like:
login (UserAuthenticateModel)
Handle user sessions: user login tokens, fetching user from session if set in session, ect' (UserSessionsModel)
...
3
votes
3
answers
962
views
Confusion on Single Responsibility Principle (SRP) with modem example?
I am currently reading through Robert Martins book "Agile Software Development" book and I am struggling to see how his modem example provides any benefit.
He says that he has an interface that ...
7
votes
6
answers
3k
views
How to know when to use dependency injection?
The question might sound a little weird, and I guess it is. I'm came up with the question while browsing through some design patterns. I came to the notorious state / strategy pattern and I came up ...
0
votes
1
answer
69
views
Object Responsibility and Calculations
Trying to work out where certain responsibilities lie with the following example.
We have a Project object and a Project can have Time entries booked against it. Each Time entry will have a no. of ...
-2
votes
2
answers
319
views
Change in constructor parameter or ways to decompose the constructor? [duplicate]
Class Book
{
private int year;
private String session;
private int volume;
private int number;
private String khand;
private Date proceeding_date;
private int pageNo;
Book(year,session,...
9
votes
8
answers
2k
views
Single Responsibility Principle Violation?
I recently got into a debate with another developer regarding the below class:
public class GroupBillingPayment
{
public void Save(IGroupBillingPayment model)
{
if (model == null || ...
14
votes
4
answers
943
views
When following SOLID, are reading and writing files two separate responsibilities?
I'm just starting to explore SOLID and I'm unsure if reading from files and writing to files are the same responsibility.
The target is the same file type; I want to read and write .pdf's in my ...
2
votes
1
answer
1k
views
When to create an in-memory object to manage repository records?
Suppose I have a conceptual Ledger that is populated with Line Items. Assume that Line Items themselves are stored in some type of persistent storage. The ledger is shown to the user who can add/...
1
vote
2
answers
1k
views
Would it be good practice to separate a user entity and a user profile entity?
When designing a system that displays information about an entity (but where modification of the data is rare or restricted to few users - such as a user profile), would it make sense to have two ...
2
votes
1
answer
552
views
Is this a good way to keep track of subscription cycles and figure out if we need to charge the subscriber?
I'm working in PHP and building a subscription management system from scratch.
I'm trying to figure out the required functions for the Subscription interface (OOP) that need to be implemented by ...
2
votes
4
answers
274
views
Is creating "shortcut methods" in the superclass of a controller Bad Practice?
Consider the following simplified example:
abstract public class Controller {
protected final boolean isUserAdmin() {
return getServiceContainer().getUserService().isUserAdmin();
}
...
7
votes
1
answer
2k
views
Clean OOP-Design: How to implement single responsibility and no procedural programming
I am currently trying to refactor a piece of C# code that is somewhat procedurally written. I want to make the design clean, object oriented and using classes with single responsibilities.
The code ...
12
votes
6
answers
1k
views
How to avoid violating the SRP in a class to manage caching?
Note: The code sample is written in c#, but that shouldn't matter. I've put c# as a tag because I can't find a more appropiate one. This is about the code structure.
I'm reading Clean Code and trying ...
1
vote
1
answer
146
views
Stuck on design when attempting to create an object store
I'm working on a small scale API project but as it will be used and maintained by people that are not Software Engineers to trade I am attempting to keep the design as separate and identifiable as ...
3
votes
3
answers
170
views
How to understand if a property is a member of a class or I have to create a different class that holds it?
Sometimes when you create a class you can add there several properties (new data members) that you are not certain if you want to do or not. For example, I have a casino slots game. I have tiles and ...
0
votes
2
answers
165
views
How to better define SRP and "wholesome" objects? [duplicate]
Assume you have a class. It can really be any class that defines a domain concept like an employee, a product on an e-commerce site, or a car. One of those examples that are oldies but goodies. ...
2
votes
2
answers
1k
views
How to avoid god controller classes and keep single responsibility principle?
The task is to make a migrator from Old DB to New DB using OOP Single Responsibility Principle.
My problem is how can I make this without making the controller a God Class or breaking the single ...
1
vote
2
answers
253
views
Object oriented Classes and single responsibility [duplicate]
I'm reading a book that explain that it is a good thing that classes have a single responsibility, that is, that they do a single thing.
I can understand how to implement this in some cases I ...
1
vote
1
answer
323
views
Confused about implementing Single Responsibility Principle
Please bear with me if the question looks not well structured.
To put you in the context of my issue:
I am building an application that invoices vehicles stay duration in a parking. In addition to ...
3
votes
5
answers
2k
views
Lots of classes with only one single static method with same name as class - Code smell? [duplicate]
I'm trying to follow the single responsibility principle (SRP) in my applications. I have lots of CRUD classes I just name xxxxxManager.
Following the SRP, I made 4 classes for each one :
...
6
votes
2
answers
1k
views
Does increasing the number of classes increase code complexity? [duplicate]
To illustrate the question, let's say we have two programmers of comparable skill that both solve the same problem. The code they turn out has roughly the same lines of code, but one programmer uses 5 ...
9
votes
3
answers
3k
views
OO - are large classes acceptable? [duplicate]
Despite many years in IT, I still struggle with OO design. One particular problem I seem to keep ending up with is large classes, often containing many hundreds of lines of code.
The OO world talks a ...
5
votes
4
answers
2k
views
Is this a Single Responsibility Principle violation?
I'm designing an OO graph library and at the moment I'm trying to figure out the design for a GraphEdge class. I've added setters and getters for it's nodes, direction and weight. This seemes ...
7
votes
2
answers
1k
views
Is it good to have an interface plenty of methods which belong to different concepts, just to preserve the Liskov's Principle?
I'm currently studying a course based on Software Design and I had a discussion in class with my professor and some classmates about a problem represented by the next scenario:
Scenario
Imagine we ...
3
votes
2
answers
530
views
Architecture Best Practice (MVC): Repository Returns Object & Object Member Accessed Directly or Repository Returns Object Member
Architecturally speaking, which is the preferable approach (and why)?
$validation_date = $users_repository->getUser($user_id)->validation_date;
Seems to violate Law of Demeter by accessing ...
23
votes
7
answers
4k
views
Does multiple inheritance violate Single Responsibility Principle?
If you have a class which inherits from two distinct classes, does not this mean that your subclass automatically does (at least) 2 things, one from each superclass?
I believe there is no difference ...
4
votes
2
answers
270
views
Should these concerns be separated into separate objects?
I have objects which implement the interface BroadcastInterface, which represents a message that is to be broadcast to all users of a particular group. It has a setter and getter method for the ...
11
votes
2
answers
2k
views
When following SRP, how should I deal with validating and saving entities?
I've been reading Clean Code and various online articles about SOLID lately, and the more I read about it, the more I feel like I don't know anything.
Let's say I'm building a web application using ...
17
votes
5
answers
1k
views
Is SRP (Single Responsibility Principle) objective?
Consider two UI designers who want to design "user attractive" designs. "User attraction" is a concept that is not objective and only resides in the mind of designers. Thus designer A could for ...