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
5
votes
2answers
282 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? ...
0
votes
1answer
9k 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
1k 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
248 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
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 ...
3
votes
1answer
2k 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
144 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
56 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
72 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
270 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
143 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
1answer
165 views

Classes to manage perks to be added and removed

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 ...
6
votes
1answer
248 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 ...
8
votes
1answer
535 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 Makes ...
8
votes
1answer
216 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, ...
1
vote
1answer
71 views

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

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
628 views

Downcast all elements from a list using static_cast

So I have this code: ...
1
vote
0answers
981 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 ...
7
votes
2answers
243 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
657 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
1k 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
3k 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
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: ...
2
votes
2answers
855 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
104 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
3k 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
500 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 ...
7
votes
2answers
553 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
114 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
99 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 a)...
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
122 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 ...
3
votes
2answers
5k views

DAOs for Person, Employee, Staff, etc

I have an abstract PersonDao class, extended by several other DAO classes, for example EmployeeDao, ...
15
votes
2answers
2k views

Encapsulated text-based RPG using a randomized combat system

For my rags-to-riches submission, I've decided to improve this code: Text-based RPG game using classes However, I've decided to start off with something different. The original code is more ...
2
votes
1answer
187 views

Many interfaces and lots of inheritance vs few interfaces and less inheritance? [closed]

I have a Visual Studio Solution which has a bunch of Projects in it. One of these projects is called "Services" and is basically the junction point between all remaining projects. When I built it ...
2
votes
0answers
150 views

Namespace handling and inheritance managing with Node.js

The following code should solve these issues: Handle namespaces; Be a class factory from Pojos Be a object factory Create a class with inheritance capabilities from a POJO using john resig ...
5
votes
2answers
174 views

Interface for a transformable grid

I am working on an XNA project, and since procedural generation is likely to be used, I wanted to eventually create a helper class to work with data to facilitate that. Design Goal: Originally, I ...
2
votes
1answer
4k views

Using a decorator to apply an inherited method to all child objects of the inherited type

I wanted to share this and get some feedback. My goal was to be able to have an object with methods: ...
5
votes
3answers
115 views

Cons of declaring derived class type member in another derived class (both of which share the same base class)

I'd like some input on the way I've structured some things in a side-project I'm working on. I declare an abstract class, CelestialObj, which will contain the ...
10
votes
1answer
2k views

Static Multilevel Inheritance with CRTP (Fast Intrusive Pointers)

I wanted to have a way to be able to static_cast to the proper derived type pointer of a base class to simulate a virtual call. Here the virtual call is for a ...
2
votes
1answer
84 views

JavaScript mixins, extending and super methods

I've read a lot of stuff about mixins, inheritance and such, and in the end I came up with this solution for extending a class with multiple mixins. I haven't seen this anywhere else... Is this a ...
3
votes
0answers
151 views

Implement.js JavaScript module pattern

I have been playing with a new JavaScript module pattern to see what I can come up with. I think it's quite powerful and wanted to know if it is something people would find useful? I'm looking for ...
2
votes
3answers
4k views

Call method of specific parent class

This question is related to this topic. Context: ...
4
votes
1answer
104 views

Merging with different modules

We have an action merge for two projects. In the projects we have different modules like Feed, Files, Post etc.... ...
2
votes
2answers
163 views

Is my code overdesigned? Does it rely too heavily on interfaces? [closed]

Context: I am using XNA to create a simple game / learning project. Problem: I have three interfaces, each with a different purpose in mind. However, the way I use them, as well as their ...
8
votes
4answers
6k views

Basic Postfix Calculator in Java

I recently posted some sample code that I was providing students with and got great feedback so figured I post another one of the examples I will be providing students with. (See Simple Example of an ...
6
votes
5answers
754 views

Initializing JTree

I have a class called Piece, and many many subclasses of Piece. I want to add an instance of every single subclass of ...
5
votes
1answer
2k views

Having children call parent's public events with data generated from a protected event

I don't know that my title describes the code I want reviewed. Hopefully the code is explanatory. I have an abstract parent class with two children. The parent listens to some hardware notifications ...