All Questions
12 questions
2
votes
4
answers
2k
views
Is a class with a high number of member variables bad and is there a design structure for data processing?
Context: Java, fairly new developer
I have inherited code from a friend for a project that processes variables. The first thing i notice is the class has a ton of member variables. I have always been ...
1
vote
1
answer
476
views
Design Chess - Object Oriented Design
I am trying to design online chess game(figuring out required classes). Need some suggestion on choosing better option to validate the move. So, lets say, I have below class
Option 1 :
My ...
1
vote
1
answer
171
views
How to add supporting information to the existing java object?
Is there a way or design pattern to add supporting information to the existing java object?
Example I have a model class Parent and it has child models. Its nothing but hibernate entities with parent-...
1
vote
1
answer
242
views
Let a subclass determine the implementation of its superclass field(s)?
Say I have two classes abstract class A, class B extends A, and I let A has a private field of type List<String> to indicate that every subclass has a field of type List<String>(so I don't ...
0
votes
4
answers
375
views
methods that has only behavior and not manage class state, is that violation of encapsulation
This is a simple scenario in an office with employees and their manager.
In this scenario, both managers and employees have a name attribute.
Only the manager can change his own name
Only the ...
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
{
...
6
votes
4
answers
35k
views
A DTO class having an ArrayList of its own type - is this considered a good design?
I came across a DTO class like the below one.
class PersonDTO {
private String firstName;
private String middleName;
private String lastName;
private String dob;
// some 50 fields ...
1
vote
1
answer
170
views
Can the has-a relation in OOP become ambiguous or difficult to know?
Assume I have the following code.
class D { static Integer i1 = 42; }
Is it true that D has an Integer? Or is it only for instance variable that we can have a has-a relation?
I also wonder about ...
3
votes
2
answers
4k
views
Class design for writing multiple versions of multiple files
I am writing a web service in Java which reads some information from a DB and generates multiple JSON files which are written to S3. For each type of file, I have a POJO which is serialized to JSON ...
5
votes
3
answers
1k
views
When is an object of real world a (computational) object in OOP world?
In an OOP design phase strategy,
Any physical/conceptual object of a system can be modeled(considered) as computational object in your OOP designed program based on below two conditions:
First ...
0
votes
3
answers
9k
views
Have Superclass Contain List of Subclass?
For the GUI of a program, I want it to list several items, all of which are, from a programming side, just subclasses. They can add one of these items to a list. I don't want to hard-code which ...
3
votes
2
answers
5k
views
When to use inheritance or composition/aggregation?
In general, how do I decide whether to use make a class a super class, or to make it a private data member of another class? For example, given two classes, how does one decide whether to do this:
...