All Questions
29 questions
0
votes
5
answers
2k
views
Comparing Java objects with different member variables
I have a base class "People" which two other classes inherit from: Employee and Student. The Student class includes a GPA (type double) and the Employee class does not. I have an ArrayList ...
2
votes
1
answer
334
views
Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?
I have the following classes, which have quite similar method implementations. Only the classes' method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case ...
0
votes
2
answers
890
views
Object Oriented Design for chess
Recently I came across some article on Chess OOPS design.Following is some snippet from it:
public class Chess {
ChessBoard chessBoard;
Player[] player;
Player currentPlayer;
List<...
3
votes
2
answers
179
views
Composing and Inheriting from the Same Type
To start off with an example: I have a read-only Repository used for getting arbitrary values. This behavior can be implemented multiple ways.
I also want to allow opt-in mutation of the repository's ...
1
vote
2
answers
202
views
Need good design: Anemic Model, Inheritance and Pattern Matching
I have Handler classes which accepts Queries and returns Results. Handlers is anemic. They accept input data bag and returns output data bag. Handlers can be many so I created common generic interface ...
4
votes
1
answer
2k
views
Delegate vs Forwarding in Java OOP
I'm reading some article about "prefer composition over inheritance", and heard about Forwarding and Delegation. After search for the different I found some source:
https://en.wikipedia.org/wiki/...
0
votes
1
answer
2k
views
Java convention - Implementing two similar functions for two different objects
I have two classes, let's call them Foo and Bar. They both extend different classes (Foo extends X, Bar extends Y), which have some common ancestor "way up" the inheritance tree, something like this:
...
-1
votes
1
answer
117
views
How to Model below Hiearchy with OOP
Note that I cannot use static inheritance due to language limitations (Java).
There is a general Building class. Each instance of Building has properties that exist regardless of instance variables (...
0
votes
2
answers
297
views
Classes as parameters
I would like to write a data structure implementation in Java that uses caches as a core part of its functionality, and I would like the user to be able to provide their own cache implementations that ...
1
vote
1
answer
93
views
Object passed to super() referenced by subclass - Any Violations?
This is the code in question, comments point it out:
class Actor extends Entity {
private MutableVector2f position;
private MutableIdentity identity;
public Actor(MutableVector2f ...
4
votes
2
answers
2k
views
Inheritance and factory together?
I have a hierarchical data model and am trying to implement their CRUD operations in my Web Application.
Currently I have code inheritance for CRUD operations of my entities (resources) as follows:
...
7
votes
3
answers
425
views
Composition of two classes with common inheritance root
Hope your day is going well.
I want to make the following composition of two objects with the same inheritance root:
There will be 3 basic operations on the Wallet class: add, getCards and ...
3
votes
2
answers
2k
views
Creating Instances from same SuperClass Object
I have 3 subclasses (LowState, MediumState, HighState) which derive from the same superclass (State).
Within the superclass, State, I have declared several variables which need to be accessed and ...
38
votes
5
answers
9k
views
When should I extend a Java Swing class?
My current understanding of Inheritance implementation is that one should only extend a class if an IS-A relation is present. If the parent class can further have more specific child types with ...
0
votes
1
answer
4k
views
How do you write super() in the UML format?Is it correct to write super(parameter: type): return type in the UML methods section?
Suppose you write a subclass that extends to a certain class and in that subclass, you use the super() method for your constructor.
Would you write "super(parameter: type): return type" in the UML?