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

7
votes
1answer
172 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
81 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
131 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
51 views

Representing trajectory points using inheritance

Problem Background I need to represent trajectory points and trajectories (encapsulating these points) in the form of a collection of classes. All trajectory points have two essential elements: time ...
3
votes
0answers
38 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
50 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
103 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
109 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
59 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
119 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
58 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
53 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
175 views

Implementing sequence abstraction

Below is the code that implements sequence abstraction using type abstraction Sequence (in Java): ...
4
votes
1answer
107 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 ...
16
votes
5answers
3k 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
161 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 ...
10
votes
2answers
424 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? ...
0
votes
1answer
140 views

A Singleton Base and derived class

I have a base and derived class since I need to have different kinds of concrete classes. I cannot use the getInstance() function in the base class since I cannot ...
2
votes
1answer
233 views

Creating users with different roles using .Net Identity 2.0 within Entity Framework

I am using .Net Identity 2.0 with Entity Framework 6.0. I have a Person class inheriting IdentityUser. I have a ...
2
votes
1answer
154 views

Dumping fields from Python objects

I am writing a small class that has one method: get_state. It is parameterless and returns a dictionary of all the names in self (look in its dict) that are not ...
8
votes
2answers
266 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 ...
3
votes
1answer
112 views

Generating a zoo of animals

The pattern I've come up here is for the AnimalGenerator itself, outside of the (abstract) Factory Pattern used within it. The factory classes themselves are not ...
8
votes
2answers
96 views

Inheriting methods of an immutable type

In my project, I have a type BalanceByBucket that is an immutable type and has a bunch of methods. I have another class called a ...
3
votes
1answer
48 views

Emulating class extending

I'm using the following piece of JavaScript to emulate class extending. Is this a valid way to go or does it have some drawbacks which should definitely be fixed? ...
3
votes
1answer
64 views

Seeking proper system for pairing types

My code below ensures that only land animals can be a "representatives" for Land while only ocean animals can be representatives for ...
2
votes
1answer
225 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
76 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 ...
6
votes
0answers
90 views

Possible class redundancy and improper enum usage

I am looking for code correctness and design usage as I think I might be over doing it in the class department. There are two things I'm mostly concerned with. The possible redundancy of classes ...
4
votes
1answer
118 views

Implementing simple and fast inheritance in JavaScript

I have been using the John Resig JavaScript class implementation in my web apps, but the tests shows it is really slow. I really find it useful for the way of extending objects, and the benefits got ...
7
votes
1answer
232 views

Multiple inheritance with JavaScript with support of calling of super() methods

I have just finished working on a Node.JS module that provides "multiple inheritance that works". I had some really specific requirements: Works in safe mode Auto-calling of parent constructors ...
7
votes
1answer
102 views

Polymorphic animals speak their name and make a noise

I'm new to GNU Smalltalk. I'd like to port a script I've written in Ruby, Scala, CoffeeScript, and several others. It's the one I use to try to learn the classic OOP concepts of abstract classes, ...
3
votes
1answer
47 views

How can I ensure some structure for classes for a plug-in system written in Python?

I have written a toolkit (hwrt) which has a plugin system. One type of plugin is a feature (see this) for many of them. There are some restrictions of feature ...
2
votes
2answers
112 views

Downcast all elements from a list using static_cast

So I have this code: ...
1
vote
0answers
128 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
178 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 ...
6
votes
2answers
116 views

Using a CRTP approach for loading OpenGL programs

I wanted to try using CRTP (also new for me) to try making the loading of shared resources implicit. (Specifically I'm using it for loading OpenGl shader programs) This will also help separate some ...
3
votes
1answer
113 views

Implementing binary output to a file in C++11

I would like to have a class which supports outputting bits into a file. This is what I came up with but I fear there are many poor decisions. Should I inherit from a ...
4
votes
2answers
119 views

Setting a common background image on a dozen screens

Is there something as "they have too little in common to use a superclass"? In my case, doing iOS programming, in a project, every screen has the same background. So I created a superclass which only ...
4
votes
2answers
136 views

Inserting and displaying books

I'm trying to write a program where you can insert and display some books (without using a database). For doing this, I use three classes: Book - is the base ...
8
votes
1answer
974 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: ...
2
votes
2answers
198 views

Custom TextBox control: AppendLine

Is there any way to improve this simple addition to the textbox control: appending a new line? ...
5
votes
1answer
64 views

Object.extends in JS

I built an easy inheritance implementation for JavScript that works similar to other OO languages and wanted some feedback on it. This works perfectly how I'd like it to, but I've read a lot of ...
6
votes
2answers
582 views

Simple PHP inheritance using an abstract class

I have created simple class inheritance of an abstract class Pet which is basically the skeleton of all other children classes. ...
5
votes
3answers
459 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 ...
6
votes
2answers
341 views

Layer Stack class to practice std::shared_ptr

The following three source files is to define and test a class StackLayer. While it was written in a need for scalable layer-based architecture design, it was also ...
1
vote
1answer
83 views

Duplicate code in similar classes where I cannot add more inheritance

I'm building a .NET Linq-esc query builder for my application and I'm wondering about my implementation and code structure when it comes a few classes. Basically I'm creating a query builder for SQL, ...
3
votes
3answers
80 views

Working with Classes (inheriting), @ properties and Initialization

I'm working on this Objective C programming assignment I found online. I'm not sure if I have met all the requirements, especially part C. Any help or suggestion will be appreciated. Part 6 ...
14
votes
4answers
2k views

Reusability vs simplicity in a small game with a set of interfaces

I have a small game I'm working on with a set of interfaces: IHavePosition: ...
2
votes
2answers
86 views

Generate the Norwegian equivalent to social security numbers - follow-up

First of, here is my previous post. That should explain a fair bit. The reason I'm posting one more time, is I have changed a lot. Using more classes, let them do all the work, and the overall ...
1
vote
1answer
132 views

Simple JavaScript inheritance

I'd like to know what you think about my implementation of inheritance. It's pretty small and intuitive I think, but I don't know if there are any drawbacks. I really want to keep it as simple as ...