Linked Questions

3
votes
5answers
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 : ...
2
votes
3answers
1k views

How and to apply Single responsibility principle correctly? [duplicate]

From Wikipedia on Single responsibility principle SoC ... class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be ...
0
votes
1answer
622 views

Rich Model vs God Class [duplicate]

I have a legacy code containing some behaviour classes, like services and controllers. My model is pretty anaemic. It's just a repository of getters and setters, and I want to refactor it. There is a ...
1
vote
3answers
197 views

Programming to an Interface and Interface Segregation in the Context of a User Class [duplicate]

I try to program to an interface whenever possible, but its not clear to me how I could apply it to a model as broad as a user. Which can hold many disparate fields (name, age, phone number, ssn, etc.)...
0
votes
1answer
194 views

Design: Bridge Game [duplicate]

I'm making revisions to a Console version of contract bridge I made in Java. The source can be found here: Bridge So most of the code is terrible and I've been trying make improvements wherever ...
1
vote
0answers
64 views

When to make classes that do multiple things? [duplicate]

When is it advisable to write a class that can do multiple things? A bit of background: my boss prefers to write things that can be used over and over again. While I tend to agree with this sort of ...
63
votes
11answers
11k views

Does this class design violate the single responsibility principle?

Today I had an argument with someone. I was explaining the benefits of having a rich domain model as opposed to an anemic domain model. And I demoed my point with a simple class looking like that: ...
44
votes
8answers
10k views

What is the real responsibility of a class?

I keep wondering if it is legitimate to use verbs that are based on nouns in OOP. I came across this brilliant article, though I still disagree with the point it makes. To explain the problem a bit ...
24
votes
4answers
14k views

What is the limit to the number of a class methods?

In different design books that I read, sometimes big emphasis is put on the number of methods that a class must have (considering an OO language, as java or C# for instance). Often the examples ...
8
votes
4answers
4k views

Is it a bad practice to separate the unit tests for a class? [closed]

My Classes normally have about 5-20 methods maximum, that implies that the class that has the unit tests has about the double of methods (counting dataProviders, setUp, ...) I have thought to ...
7
votes
5answers
615 views

How do you define a responsbility?

I learnt the SOLID principles back in 2011 and I try to use them in my day to day work. However, I often find myself wandering if I am breaking the Single Responsibility principle. A class can have ...
9
votes
7answers
1k views

Am I making my classes too granular? How should Single Responsibility Principle be applied?

I write lots of code that involves three basic steps. Get data from somewhere. Transform that data. Put that data somewhere. I typically end up using three types of classes - inspired by their ...
8
votes
3answers
546 views

Does it violate the Single Responsibility Principle if an object knows how to change itself?

I have worked with examples like a Player object which knows how to change its own state. Another example, is an Invoice object which knew how to calculate its invoice charges using an algorithm. ...
3
votes
3answers
9k views

Designing a parking lot

Description: Given a parking lot containing multiple levels and each level containing multiple rows and each row in turn containing multiple spots. The questions is to determine if there are enough ...
0
votes
3answers
333 views

Automating checks for “good” unit tests

There's already a question about How to write good unit tests. Based on the answers provided there, the key properties of a good unit test - Short Readable and conveys intent instantly Independent ...

15 30 50 per page