Skip to main content

All Questions

Tagged with
14 votes
6 answers
3k views

Clean OOP way of mapping an object to its presenter

I am creating a board game (such as chess) in Java, where each piece is its own type (like Pawn, Rook etc.). For the GUI part of the application I need an image for each of these pieces. Since doing ...
3 votes
3 answers
1k views

Should business logic classes be POJO only?

I read about three-tier architecture and I have a question: I read that in business logic (that is, what is in logic tier) there should be POJO classes, but in most Spring manuals these classes are ...
2 votes
1 answer
1k views

In Python when is absolutely preferable to use a class instead of a module?

Python is the language I use most in this period. My background in Java Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
-4 votes
3 answers
224 views

Java OOP problem

I'm working on a Java programming assignment. In this assignment, there's an immutable class Book and a mutable class BookCopy. You can have multiple BookCopy of the same Book. Now here comes the ...
66 votes
11 answers
65k views

In Object-Oriented Programming, why is it generally desirable to split a program into multiple classes? [closed]

After studying Programming through books, they have taught me concepts such as inheritance, but never explain how splitting a program into multiple classes helps with anything. Yet, many books seem to ...
16 votes
7 answers
44k views

What is the better way to escape from too many if/else-if from the following code snippet?

I am trying to write a servlet which does task based on the "action" value passed it to as input. Here is the sample of which public class SampleClass extends HttpServlet { public static void ...
6 votes
4 answers
1k views

How to avoid init methods when 2 objects need the reference of each other?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first ...
4 votes
6 answers
2k views

The ID of an object is null at start. Does that make the object state invalid and violate encapsulation?

This question is related to How should an `Employee` class be designed? In the above question, to uniquely identify an employee, each Employee object has an id field as shown below class Employee { ...
-1 votes
1 answer
4k views

If I have 2 different implementations of the same interface but with the same methods should I have 2 interfaces? [closed]

I have 2 different implementations of the same interface, but each one of those objects have different implementations, however they have the same methods, should I create one interface for each type ...
6 votes
2 answers
3k views

Trouble with circular dependency in state machine design

I am trying to develop the structure for a basic state machine that can also take in input and produce output. I've hit a bit of a mental block in trying to figure out how to model the relationship ...
25 votes
4 answers
42k views

Service layer returns DTO to controller but need it to return model for other services

Following this post https://stackoverflow.com/questions/21554977/should-services-always-return-dtos-or-can-they-also-return-domain-models and best practices in Software Arch suggestions by Martin ...
0 votes
3 answers
354 views

How to refactor "init()" into "physically make them two separate classes"?

According to https://softwareengineering.stackexchange.com/a/334994/432039, I know "init()" method is a code smell, and "physically make them two separate classes" is a way to ...
14 votes
5 answers
5k views

How to "Tell, don't ask" when 2 objects involves in the condition and the decision at the same time?

According to Explanation on how "Tell, Don't Ask" is considered good OO, I know the following is bad: if(a.isX){ a.doY(); } public class A{ public boolean isX; public void ...
0 votes
2 answers
417 views

How to restrict the construction of a domain object to an external service?

I have this object RelativeFoo{int relativeCode, Origin relativeTo} And I want to map it to this other object AbsoluteFoo{int absoluteCode} In order to do this, I need to use a service whose ...
3 votes
5 answers
993 views

How are strings simultaneously objects and primitive data types in C#?

In C#, strings can be used like objects with methods, properties, and other features of objects. At the same time, strings are treated the same as primitive data types like int or float in numerous ...

15 30 50 per page
1
2 3 4 5
33