Skip to main content

Questions tagged [inheritance]

Inheritance is a way to reuse code of existing objects, or to establish a subtype from an existing object, or both, depending upon programming language support.

Filter by
Sorted by
Tagged with
0 votes
2 answers
335 views

I have a question about setting up my service. My main concern is if the design is clean and in order. Whether it meets the SOLID principles and does not spill out on me. I have entities like order ...
Petr Klekner's user avatar
2 votes
3 answers
324 views

I have a Slide class with subclasses referring to the different types of slides (IntroSlide, SummarySlide, etc.): abstract class Slide { String slideType; final String title; final String ...
Hello's user avatar
  • 47
2 votes
3 answers
271 views

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare most abstract type when possible, for example, suppose I'm using an UI ...
wcminipgasker2023's user avatar
5 votes
2 answers
765 views

According to Is it bad practice to use Inheritance to associate methods with a basic container?, I know it is bad to inherit form std containers, mainly because std containers are not designed to be ...
wcminipgasker2023's user avatar
5 votes
4 answers
2k views

Let's say we have 2 (Java) classes: class A {} class B extends A {} To me, saying B extends A and B is dependent on A are both true (but not equivalent) in this situation. My colleague, OTOH, says ...
TheJavaGuy-Ivan Milosavljević's user avatar
2 votes
1 answer
398 views

When you define a class, is inheriting a logger such as log4cxx a good design? Assume I am defining a class called MyClass. When I want a logger, I use a pointer to an abstract logger class as a ...
Dhammika Wijesundera's user avatar
1 vote
4 answers
1k views

I know you can't inherit static methods, and it seems the consensus is that if you feel like you need to, you're doing something wrong. However, I don't know what the alternative is in my case. Please ...
Andrew's user avatar
  • 21
0 votes
5 answers
2k views

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 ...
Delta88's user avatar
  • 19
0 votes
2 answers
404 views

According to Why is Clean Code suggesting avoiding protected variables?, I should avoid protected variables because of the reason : "closely related concepts should not be separated into ...
wcminipgasker2023's user avatar
2 votes
2 answers
157 views

For example, for base and child classes, if all child class need a class member, eg: baseHp, which represents the base hp to calculate the actual hp of monsters in a game: public class Monster{ ...
wcminipgasker2023's user avatar
15 votes
6 answers
6k views

In C# and C++, an apparent trend is in place to reduce / avoid inheritance: C#: "Sealing types can improve performance." https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/...
user avatar
2 votes
2 answers
505 views

I've been reading this Wikipedia article Composition over inheritance. It gives a code example of inheritance first, and then a code example of composition. In case of inheritance there are data that ...
Andrew Savinykh's user avatar
0 votes
0 answers
589 views

Because I have multiple entities with unique fields, I need multiple repositories for each one even though each Entity will be handled exactly the same. What is the best way to handle these separate ...
dbrewster's user avatar
  • 139
1 vote
1 answer
213 views

Suppose I have some Java code such as the following (in this case, the use of the name "interaction" is referring to interacting with an object in a video game): public abstract class ...
micheal65536's user avatar
-1 votes
3 answers
656 views

I am creating the backend of a microservice that will serve as a tool to see in real time how the company's employees are distributed by projects and what days they have assigned to each one. The ...
Diegol's user avatar
  • 1
2 votes
2 answers
249 views

I am going through this nice write up on thoughtworks about inheritance vs composition. I understood the authors explanation of the dual purpose of inheritance. But, I am confused on the specific ...
kosa's user avatar
  • 159
21 votes
6 answers
7k views

In Python 3, I subclassed int to forbid the creation of negative integers: class PositiveInteger(int): def __new__(cls, value): if value <= 0: raise ValueError("value ...
swoutch's user avatar
  • 321
2 votes
4 answers
741 views

I am working on implementing some stock order types for a financial technology application. There are six different types of stock orders - market, limit, stop_loss, stop_loss_limit, trailing_stop, ...
Treker's user avatar
  • 197
0 votes
3 answers
1k views

I have an abstract class that represents chess pieces, it has an abstract method isMoveValid(Square futurePosition, PieceColor color) which checks if the piece moving to that square is valid or not, ...
Yoh's user avatar
  • 51
2 votes
4 answers
435 views

I only recently started to work with backends. My database is supposed to store information about maven-like artifacts. There are going to be applications and configuration artifacts. Now those ...
Marcin K.'s user avatar
  • 129
50 votes
7 answers
11k views

I've just started learning about Inheritance vs Composition and it's kind of tricky for me to get my head around it for some reason. I have these classes: Person class Person { public string Name {...
Octavian Niculescu's user avatar
2 votes
3 answers
1k views

I have a codebase where some classes contain both "essential" business logic, and "incidental" complexity. I am considering a refactor where I leverage inheritance to improve the ...
MYK's user avatar
  • 343
0 votes
2 answers
1k views

I have two repositories: class RepositoryOne { /** * @param int $id * @return ModelOne */ public function getById($id) { // Search and find a ModelOne model in the ...
pro100tom's user avatar
  • 449
3 votes
2 answers
1k views

I've recently found myself using a generics with constraint that a type should inherit from a specific base class, but now I've just realised that this is redundant and unnecessary because the ...
Piotr Golacki's user avatar
0 votes
1 answer
298 views

I want to write an application where I would delegate certain functionalities to 3rd party libraries. To make sure the code remains modular, I want to put these libraries behind an interface so I can ...
yah_nosh's user avatar

1
2 3 4 5
12