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".
3
votes
2answers
56 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
68 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
64 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
42 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
33 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
459 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
437 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
1answer
107 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
78 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
129 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), ...
5
votes
0answers
79 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
98 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
119 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
93 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
214 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
103 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
133 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
60 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
39 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
51 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
107 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
117 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
68 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
127 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
74 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
78 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
185 views
Implementing sequence abstraction
Below is the code that implements sequence abstraction using type abstraction Sequence (in Java):
...
4
votes
1answer
135 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
7k 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
176 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
546 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
490 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
386 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
177 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
309 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
161 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
101 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
65 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
228 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
83 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
96 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 ...
6
votes
1answer
148 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
254 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
111 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
49 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
139 views
1
vote
0answers
169 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
266 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
135 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 ...