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".

learn more… | top users | synonyms

-5
votes
1answer
37 views

Refactor code that violates “Needless Repition” principle [on hold]

Assume class Animal which does Eat, Sleep and Make Noise. Assume class Mammal : public Animal which also does MakesBaby Assume that Mammal also does Eat, Sleep and Make Noise which it inherits from ...
2
votes
3answers
98 views

Code Smell in Unit Testing Serialized Classes

I can feel that something is wrong with my code. Here's an excerpt where I think the code smell is... ...
0
votes
0answers
18 views

Class property holds data from database

I have a class, it has two properties: var fruitsPackId: Int var fruitsPackContent: Array<Fruit>? Once the class is ...
2
votes
1answer
67 views

Inheritence Cleanup

I have the following interface ...
2
votes
1answer
21 views

Draggable toolbar header class, inheriting from a draggable parent class

I have written a draggable parent class using a module pattern: ...
2
votes
1answer
60 views

Parsing a string containing arithmetic operations in prefix notation

This is a piece from the complete program. What it does is parses mathematical expressions of the form (+(*3,x),5) to 3*x + 5 ...
1
vote
1answer
43 views

JavaScript inheritance with super calls and mixins

I needed JavaScript inheritance that offered calling of overridden methods (super calls). Furthermore I needed a possibiliy to add behaviour to instances (mixins). Mixins should not only be full ...
1
vote
0answers
23 views

Idiomatic abstract inheritance with Go

I am currently discovering Golang, and I try to implement some random variable generation functions similar to R functions. To avoid code repetition, I'd like to use inheritance, which is quite ...
1
vote
2answers
49 views

Class inheritance testing

I'm just messing around with class inheritance. I originally had a separate goal in mind but I ended up here, and my new goal was to have a parent that was completely ignorant of it's self, i.e. no ...
0
votes
2answers
109 views

File processor for text and HTML

I recently took a test. One of the questions was to find problems in the following code and suggest refactoring which can provide adding new formats of data: ...
5
votes
0answers
71 views

Recorder for keyboard and mouse events

I'm building an event recorder. So far the code looks clean, but I feel like I'm missing something that can make this code even better. Is composition a better solution? If yes, how can I do it ...
3
votes
0answers
55 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
172 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. ...
8
votes
1answer
113 views

Extending the functionality of lxml.etree

I wrote a class to slightly customize the behavior of lxml.etree.ElementTree and I use it quite extensively. It works great, but there are a few methods that I'm ...
3
votes
1answer
112 views

Object-oriented web scraping with Python

I usually write function-only Python programs, but have decided on an OOP approach (my first thereof) for my current program, a web-scraper. Here is the working code I wrote which I am looking to have ...
1
vote
1answer
80 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 ...
1
vote
0answers
426 views

Reusable REST service class for Angular2 in TypeScript

I am creating an Angular 2 web application using TypeScript. This application performs REST requests to a REST "service". For each REST resource in my service I create a separate "Service" class in ...
3
votes
0answers
76 views

Mortgage calculator in JavaScript

I'm learning JavaScript and decided to build this mortgage calculator as a starting point. For the most part it was reasonably straightforward, but when I implemented the graphs using D3 I found ...
3
votes
2answers
184 views

Follow up - Creating Inheritance hierarchy using function constructor

In continuation with this question, Animal class has four fields: name sound ...
8
votes
1answer
116 views

Creating Inheritance hierarchy using function constructor

Problem statement You need to create the Animal base class having four fields: a. name b. ...
3
votes
3answers
211 views

Logic Gate Simulator - Proper Encapsulation

So I was checking out the courses on InteractivePython, and I came across this example to demonstrate inheritance. My focus is on the Connector class and how it ...
1
vote
2answers
64 views

Adding new articles

Following is a working program to add new articles. The only thing I want is to check if there is any way to write it in a better way, or if the architecture is good as it is. Maybe I did not have to ...
2
votes
3answers
149 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 ...
3
votes
2answers
258 views

Creating n-dimensional mathematical vector classes through inheritance

Right now I have no knowledge of templates, but I just finished learning about inheritance, and wanted to apply it to a Vector3 class that I had already created. My ...
2
votes
1answer
120 views

Sorting polymorphic classes

I'm learning from "Jumping into C++" by Alex Allain (sample chapter and TOC) and solved the first problem in Chapter 26 "Inheritance and Polymorphism". I'm especially concerned about my use of ...
3
votes
4answers
372 views

An attempt at inheritance (Geometric Shapes)

I'm reading through the chapter on inheritance from C++ Primer 5th Edition. It asks Organize the following type into an inheritance hierarchy: (b) Geometric primitives (such as box, circle, ...
1
vote
1answer
52 views

Complicated inheritance [closed]

I found the below code in our code base at work, and I think it looks strange. The class RetainCounting is used for implementing reference counting. Should the IProvider really derive from ...
4
votes
1answer
39 views

Grids, Cells, and Inheritance

I want to build a grid and I have 2 concepts: Grid which is consist of Cell. Grid class is: ...
6
votes
1answer
487 views

Creature generator

Originally posted this here, and it was helpfully suggested to post in this forum. In the past couple of years I've returned part time to programming after a 15 year gap. I was C/UNIX. So, I've ...
7
votes
2answers
464 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
192 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: ...
4
votes
1answer
103 views

The rounded box that wanted to be an arc

This is from Bjarne Stroustrup's C++ Programming: Principles and Practice, Chapter 13 Exercise 2: Draw a box with rounded corners. Define a class Box, ...
2
votes
3answers
223 views

Music collection with lyric songs and instrumental pieces

I have problems with dealing with derived classes that inherit from the same base class. I have 2 types of songs: Songs with lyrics that have: Title, Tags (sad, happy etc.), lyrics (one line), ...
6
votes
1answer
151 views

Multiple inheritance pattern for vehicle information

I wanted an easy way to augment objects, by adding functionality from any other object(s). More importantly, I needed a way to augment the object from multiple sources in a clean one-line solution. ...
5
votes
2answers
137 views

Base service for two different implementations

I have code that fetches different templates for HTML and CSS in the file system. The templates are stored in different folders, so I have two implementations for the code that fetches them, passing ...
4
votes
1answer
573 views

Optional base class template to get conditional data members

In generic code, I sometimes want to conditionally add a data member to a class template. Writing separate template specializations scales as 2^N for ...
2
votes
1answer
118 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 ...
7
votes
1answer
348 views

Creating instances of all subclasses in Python

I have a superclass with several subclasses. Each subclass overrides the "solve" method with some a different algorithm for estimating the solution to a particular problem. I'd like to efficiently ...
4
votes
2answers
212 views

Infrastructure for my 2D game using Allegro

I am making a small 2D game with the use of Allegro 5 library. I am making use of inheritance e.g. sprite class as the base class and player class as the child class, but I want to know if it's a good ...
5
votes
1answer
144 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 ...
3
votes
0answers
40 views

Assigning functions for different location classes

Suppose in a School, you can only study, teach, or walk; in a Mall, you can only purchase, walk, or sell; ...
4
votes
3answers
53 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
111 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: ...
3
votes
1answer
130 views

Using composition instead of inheritance

I have been using Entity Framework 6, AutoMapper, ASP.NET Web Api and hit a few problems along the way, each time it was recommended that I could change my code from Inheritance to use composition ...
2
votes
1answer
90 views

Generic classes with inheritance/equals/comparison operators

I would like to greatly reduce verbosity of following code fragment. What I'd like to do: Reduce number of occurrences of MaterialRangedParam<Value> and ...
6
votes
2answers
158 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 ...
4
votes
1answer
128 views

Generic Pickle-Aware Super-Class for Mixing Classes with and without __slots__ in Python

I want a generic super-class that I can easily subclass - and if desired add slots to my class - without having to worry about any pickle issues (with the lowest protocol). Is this in general a good ...
2
votes
0answers
173 views

MultiLevel JavaScript Inheritance

I'm making an experiment on JS, trying to build a framework for OOP. It's called Universe. The main purpose is to emulate a mini-universe, where classes are "created" with a defined behavior ...
3
votes
3answers
212 views

Implementing sequence abstraction

Below is the code that implements sequence abstraction using type abstraction Sequence (in Java): ...
4
votes
1answer
207 views

Calling common async code from a derived method

I'm implementing a number of classes in C# that have async methods. However, each of these methods needs to implement some boilerplate code that is common to all. Therefore I've implemented the common ...