Questions tagged [inheritance]

One of the four pillars of object-oriented programming (OOP), inheritance establishes a "is-a" relationship between objects. For example, a "Cat" object can be treated in code as any other "Animal" object because a "Cat" is-a "Animal".

Filter by
Sorted by
Tagged with
3
votes
0answers
41 views

Create, aggregate and plot signals using various methods for a given symbol using its historical data

I am hoping to get some help regarding code arrangement/organization using OOP concepts. My question is whether my usage of class/object selection/declaration and instantiation are sensible and what ...
3
votes
1answer
2k 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
45 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 ...
1
vote
0answers
75 views

Printshop database design

I am trying to design multi purpose printshop database on which I will develop my basic store system. Beofre I tried to design it using EVL (Entity-Attribute-Value) aproach, however some users would ...
3
votes
2answers
611 views

Serializing a class hierarchy to JSON

I have a hierarchical object structure which needs to be converted to JSON. I have a following basic implementation of how it will be done: ...
0
votes
1answer
72 views

Java inheritance and generics [closed]

Today i had discussion with my colleague about casting. Our case: We have root class ...
3
votes
3answers
2k 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 ...
3
votes
1answer
95 views

Vehicle inheritance exercise

I'm learning about using inheritance and super in Ruby. This is a continuation of one of the exercises that is in a book I am reading. I set up my Vehicle class to be the superclass. From there, <...
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 ...
5
votes
3answers
379 views

Inheriting from std::auto_ptr to support deletion of allocated arrays in C++98/C++03

[EDIT: Thanks for your opinions. I think this topic is discussed enough. Since std::auto_ptr is removed from C++17, I decided to drop the idea of inheriting from <...
-1
votes
1answer
675 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
220 views

Parsing various types of message strings

Similar question MessageFormat: represents the various kinds of messages. (XML, JSON, ...
6
votes
1answer
501 views

Acyclic Visitor Pattern without dynamic_cast

The goal is to minimize boilerplate code for creating visitors while allowing users to easily define custom visitors without having to add new accept methods for each visitor type. For example, a ...
1
vote
0answers
3k views

Inherit from Dictionary or create my own class with a dictionary

I'm working C# on an exercise that is it very strange. I have these three classes. ...
3
votes
1answer
117 views

Validating proper input

Verifying the user's input is almost always required, even in really simple apps such as console calculator. Due to the wide variety of scenarios where this is useful I decided to make a few classes ...
4
votes
2answers
530 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
93 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. ...
11
votes
1answer
225 views

Implementing a Maybe for multidimensional data

The scenario is we're working with a REST endpoint that gives us nice JSON objects. We're using requests, and everything works wonderfully. But one day you notice that data you though was always being ...
0
votes
1answer
91 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 ...
1
vote
1answer
82 views

Inheritance: declare a method that returns the current instance class

I have a Vector and 2-dimensional Vector, defined as follows: ...
10
votes
1answer
710 views

Subclassing pathlib.Path

This arises from the SO Question subclassing pathlib.Path. The pathlib sources show that Path, when invoked, selects one of ...
13
votes
2answers
840 views

Dynamic memory management for a class hierarchy of geometric shapes

The task was to write function that compare areas of two random generated geometric shapes (circle, square, rectangle) using base class with virtual function. Am I doing it right in terms of memory ...
3
votes
2answers
217 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 ...
8
votes
3answers
3k views

Create dictionary with default immutable keys

I've created a dictionary subclass with a set of default immutable keys. ...
7
votes
4answers
2k views

Armor and Weapon classes for a game

I have a 2 classes Armor and Weapon in my game, that inherit from the abstract class Gear: <...
1
vote
1answer
25 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: ...
19
votes
2answers
3k views

A Python wrap-around list

I want to gain experience creating data structures that look and feel like Python builtin types. As a first exercise, I've written a WraparoundList class meant to ...
2
votes
2answers
85 views

Represent a person who has different roles for different offices

People have different types of roles depending on the office they are working at. For example, a person has two roles (cashier,cleaner) at OfficeMax and five roles(manager,security,etc) at OfficeLess. ...
5
votes
1answer
1k views

Modular Visitor Pattern

Motivation I created this because the Visitor pattern felt like the most appropriate, but I also wanted to satisfy the Open/Closed principle with respect to the logic when visiting specific node ...
5
votes
1answer
4k views

Python proper abstract class and subclassing with attributes and methods

The goal of the code below is to have an abstract base class that defines simple methods and attributes for the subclasses. This is part of an application that provides the code base for others to ...
3
votes
1answer
424 views

Subclass of socket with optional TLS

...
6
votes
2answers
123 views

“Simple” generic inheritance

I'm sure that my intentions are highly erroneous, and I really just want to see what you guys would suggest I do instead. I have a class I made for my game which helps store various values regarding ...
3
votes
3answers
688 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 ...
14
votes
5answers
3k views

Mini RPG equipment code

what do you think about this code? It's upgraded version of: Classes representing items in an RPG game ...
3
votes
1answer
1k views

Classes representing items in an RPG game

I wrote a little program in C# that contains classes representing Items in RPG game. I wanted to have access to all inherited classes parameters from list contains parent Item class instances, so this ...
2
votes
2answers
1k views

Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle - follow up

This is the new code after the changes suggested by @Cody Gray in the last question: Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle This is my project on ...
8
votes
1answer
15k views

Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle

This is my project on inheritance and polymorphism. I have the main file from my teacher and built the project base on it. My base class is Shape. ...
3
votes
2answers
147 views

Loading items from XML document

I'm making a game in Unity and I need to have a inventory/item system, I decided to store my items in simple XML document which I later read from. I'm planning to have different varieties of items and ...
3
votes
1answer
628 views

Try again, and again, and again… but not too often because the potatoes won't grow

The delay sequence has been fixed so I can move to the next step which are the Retry and Breaker. (Just ignore the console ...
2
votes
1answer
113 views

Growing potatoes in delayed sequences

In order to grow potatoes I'm implementing the retry pattern. If I fail to grow them, I'd like to try it again later. The first part I've implemented is a collection of delay generators. Their base ...
3
votes
1answer
1k views

Print Professor and Student Object using Inheritance in C++

I'm a newbie in C++ (6 hours) and I have implemented this problem in C++ . I know this is a simple example but how can this be improved? Syntax wise or shortened code wise? Here is the question from ...
4
votes
2answers
5k views

Structure of inheritance between Animal classes and methods

I'm trying to do some basic inheritance between the 3 classes and use some simple methods, and I'm looking to learn what should be the correct structure between them and what can be improved. ...
0
votes
2answers
189 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 ...
2
votes
1answer
4k views

Validation of a couple of model classes using FluentValidator

A couple of model classes are doing the validation using FluentValidator. These model classes are used to Add and Edit the branch data and they are working well but ...
3
votes
1answer
72 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
190 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 ...
-2
votes
1answer
54 views

Is it ok to change implementation of parent function with child data? [closed]

I was wondering is it OK to change implementation of parent class with child class data. I have situation of creating a child class (form) which extends the parent class (other form with same elements)...
-1
votes
2answers
362 views

Swift inheritance versus composition

Say I'm using Parse Server and utilising the PFObject class from the iOS SDK. Say I want to have a Chat class. To use inheritance code (design 1): ...
3
votes
1answer
77 views

Emulating super() in Python 3.x using Python 2.7

Depending on the name of the first argument, self.__sup or cls.__sup behaves like super() in ...
1
vote
0answers
113 views

AWS Redshift wrapper class that automates similar types of loads from S3

I have a AWS Redshift wrapper class that automates similar types of loads from S3 for me, and I have recently adapted it to work for Spark jobs, which don't require a manifest, and instead need a ...