All Questions
Tagged with inheritance java
59
questions
1
vote
1answer
78 views
Reading data from multiple different resource bundle property files in Java
I have class structure to read the data from resource bundle (property files).
...
0
votes
0answers
42 views
Pool of Thread Pools
I had a problem at my work that we have some tasks that need to be executed as fast as possible. To do this we implemented them so they are multi-threaded in an ExecutorService. Originally we had for ...
5
votes
2answers
131 views
FizzBuzz game, open to any critiques
I made this FizzBuzz game for my college class and it's kind of ridiculous, but is suppose to demonstrate chain of command so writing it in a little forloop was out of the question. In case you don't ...
4
votes
2answers
100 views
Human Jug and Glass
I am a beginner in Java. I have created this small project in Java with the inheritance concept. Here the Human will fill, pour and drink water. There are three classes: Glass, Jug and Human. Let me ...
2
votes
1answer
98 views
library having two types of books
I need to make a project related to a library catalog.
It should have following methods relevant to these books:
add
delete
list
There are two types of books: novels and poetry. Both types have ...
4
votes
3answers
375 views
Abstract classes in Blackjack game [closed]
From what I've read, I should use abstract classes when I want to define behavior for a superclass, and I don't want to instantiate the superclass. So, I'm making a Blackjack game in Java, and I want ...
0
votes
1answer
2k views
A Java Quadrilateral Inheritance Hierarchy - revisited
This is an exercise from Deitel&Deitel's "Java. How to Program (Early Objects)", 10th edition.
9.8 (Quadrilateral Inheritance Hierarchy) Write an inheritance hierarchy for classes Quadrilateral, ...
-1
votes
2answers
73 views
Healthy Characters
Let's say I have an abstract class Character that have fields health and maxHealth. maxHealth...
5
votes
1answer
107 views
Classes to encode and decode images
I'm a developing a image processor, which reads a Base64 (compressed) image and writes its subimage to targets on threads.
(Constructors, exception handling, and ...
-3
votes
1answer
233 views
Use inheritance to reuse toString/equals/hashCode [closed]
Does it bad practice inherit class to reuse toString/equals/hashCode (that actually based on reflection and use actual class field for it)?
For example:
...
6
votes
4answers
866 views
Better way to add fields to superclass in Java
I'm making my first steps in OOP and I'm currently doing some exercises. I've done a simple program with class structure like this (I'll provide only essential parts):
Super class:
...
5
votes
1answer
4k views
Custom ResponseModel for Spring Controller - ResponseEntity<?>
I created a custom responseModel to have a standard json responseModel for some of my different RestController.
Superclass TransactionResponseModel:
...
1
vote
0answers
46 views
TreeBuilder to handle various kinds of inputs for UI
I have to render a menu in tree structure in our UI. I am building the tree in the backend. The Tree can be built by taking many combinations of input parameters. So I created a hierarchy of Input ...
0
votes
1answer
76 views
Java inheritance and generics [closed]
Today i had discussion with my colleague about casting.
Our case:
We have root class
...
3
votes
3answers
3k views
OOP modelling of a car agency
Exercise:
A car dealer wants a computer system to manage the data of their vehicles and classify them by type.
All cars have the following data
Engine serial number
Brand
Year
...
9
votes
1answer
2k views
OOP modeling of a boat rental system
I have some question about this exercise, did I model the problem correctly (the code works)?. If I did it correctly, Is there anything that can improve the code?. For example, how could I avoid the ...
-1
votes
1answer
993 views
How to avoid duplicate code due to the impossibility of using multiple inheritance
I'm working on a Spring - Hibernate App, and I have a question about how to correctly avoid duplicate code and using Hibernate, due to the impossibility of using use multiple inheritance (I usually ...
-2
votes
1answer
225 views
Parsing various types of message strings
Similar question
MessageFormat: represents the various kinds of messages. (XML, JSON, ...
4
votes
2answers
870 views
Getting the distance between various classes of shapes
Below I define a simple shape class with two derived classes: Point and Line which both implement the ...
4
votes
3answers
97 views
Viewing the final state of an Object
As a beginner I was writing a code which asks the burger buyer what they want in their burger. I did this by creating a burger object and modify its attributes by the user using a switch case method. ...
0
votes
1answer
97 views
Call method if child implements interface vs override [closed]
I have a hierarchy like next:
AbstractRequestWs
|- CreatorRequestWs
|- CheckRequestWs
|- GetRequestWs
|- DeleteRequestWs
In this implementation I ...
3
votes
2answers
411 views
Calculator for the area of various 3D figures, using abstract classes and inheritance
I am a Java newbie, and they have just recently taught us abstract classes and inheritance. While I was practising, I wondered whether I can make multiple instances of the same abstract method in ...
1
vote
1answer
28 views
Multiple Interfaces modifying contract
I have a problem with my interface-design. I especially ask for help with the overloaded compute-Method.
For a calculator I work with these Interfaces:
...
3
votes
3answers
885 views
Models an assembly line
The gist of the code is that there's an assembly line of products, in this case Toy and Book, that get inspected by workers who then add them to a box. The box is then sent to someone who knows what ...
0
votes
2answers
219 views
Very complicated Java HelloWorld app
This program attempts to shows the basic concepts of inheritance and polymorphism. In what ways could the code be modified to better demonstrate those concepts? The interface, abstract class and the ...
3
votes
1answer
79 views
Map object types using custom converter
I'm trying to design a mapper that will convert one object type to another shown in the diagram below:
The object has structure as follows (it's not a JSON):
...
0
votes
4answers
209 views
Multilingual command handler using inheritance
My problem is that you have a lot of ifconditions to be checked and inside that if condition you have multiple lines of code. I ...
3
votes
1answer
831 views
Extending functionality of org.springframework.batch.item.file.transform.DefaultFieldSet
I would like to be able to set token values (defaultFieldSet.tokens) and names (defaultFieldSet.names) on ...
3
votes
0answers
785 views
Shape inheritance hierarchy
I have managed to build an inheritance hierarchy for shape class object and I am wondering if there is a better solution to combine the following 2 hierarchies.
To begin, I have a 4 shapes classes ...
4
votes
3answers
883 views
Swing GUI in Java
I'm learning Java at the moment and I'm currently trying to make a GUI using Swing. I've done some reading and people usually prefer and advice to use composition instead of inheritance of e.g. ...
1
vote
1answer
213 views
Restricting types not related through inheritance without using instanceOf by creating own class hierarchy
Restricting types not related through inheritance without using instanceOf by creating own class hierarchy. It needs to interact with a key value data store, will ...
2
votes
3answers
1k views
Polymorphically processing 2 & 3 dimensional objects
It seems there are a lot of "empty containers" (I do not know the correct, technical term) with regards to multiple levels of abstract classes and functional interfaces with little or no code. Is ...
7
votes
2answers
572 views
Java - Something similar to Abstract Factory?
I have many repositories stored in a map. User chooses some of them and then a downloading begins. Repository may be one of 4 types (see code below).
...
3
votes
2answers
551 views
Reuse a base class [Activity] handler in all sub classes for background work
We are using the Thread of a common base class but using its handler in all its sub classes. The code is working fine but is it the right way to go about?
Our base class looks like this:
...
2
votes
1answer
769 views
Lockable linked list
The existing design of class DList and DListNode is taken. The main criteria is to do successive updates in \$O(1)\$ time.
Part ...
6
votes
1answer
330 views
Code Golf challenge that plays Mafia
I am working on writing a Code Golf King of the Hill challenge, the details of which can be read here. You can read the full code here.
Briefly, the game proceeds in cycles of night then day. There ...
4
votes
3answers
390 views
Page Enum with overridden methods for the first and last members
I am managing the changing of views in an Android app using this enum and associated methods. I am particularly interested in the Page enum's use of overriding <...
2
votes
3answers
143 views
Is one-sided equality more helpful or more confusing than quick failure?
My question is about the equals() method. Most people implement equals() to start like:
...
6
votes
2answers
690 views
System for registering people
For a small administrative program, I have to be able to register people and their data. But, files are sometimes created through a phone call "on the fly" and then later certain data is added to the ...
3
votes
3answers
299 views
Implementing sequence abstraction
Below is the code that implements sequence abstraction using type abstraction Sequence (in Java):
...
35
votes
5answers
193k views
Implement a Shape abstract class
To learn more about OOP, @nhgrif challenged me to implement a Shape abstract class (more details in code remarks below. Here is how I did it. Any and all advice appreciated!
Shape.java
...
5
votes
2answers
296 views
Strategy Game Menus and OOP
Most of my experience is with Objective-C, so I am relatively new to Java inheritance. I understand that there are concepts such as abstract classes and interfaces, but I am still not totally sure ...
11
votes
2answers
4k views
Decomposing the animal kingdom
I have implemented a Mammal class hierarchy in Java.
Is it an intelligent approach, with respect to decomposition, locality and procedural abstraction?
...
9
votes
2answers
2k views
Video Store Rental Application
I'm in the middle of developing a video store rental application for a school project but am starting to question whether I'm going about things in the correct manner. Although the application is ...
2
votes
1answer
279 views
Displaying a list of players and their leagues
My question is mostly directed towards the principles of object-oriented programming.
I have an Android application and one of the activities has a ListView.
In ...
4
votes
1answer
151 views
Design/reiterate or code reuse for linked list
This is what my class hierarchy looks like. I have an abstract superclass, AbstractLinkedMyList, that contains common operations for both sorted and unsorted linked ...
1
vote
0answers
1k views
Testing with multiple input datasets and expectations
I wanted to make 3 test suites where each would run a test class with a specific input. I figured that in order to do this I could:
Make an abstract test suite with all the variable parts (...
4
votes
2answers
2k views
Should I create an abstract runnable? I've 4 sub-classes which perform similar work but only 3 of them have identical constructors
I've added the code for an abstract thread class and 2 sub-classes. The structure and job of the threads (sub-classes) is identical except one difference: ONE of ...
8
votes
1answer
7k views
Solar System model: Moving Space Balls
I have a model of the solar system that I'm working on at the moment. Now is the time to start cleaning my code up a little.
Here's what I have so far:
A main 'driver' method:
...
5
votes
3answers
516 views
DRYing out some Java code and tests
I am writing some tests that all follow the same pattern, I feel like repeating myself over and over again, how can I reduce the repetition? The (almost) repeating part is in constructor and the class ...