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".
14
votes
4answers
749 views
Modelling a Call Center
This is the requirement I have (from the book: Cracking the Coding Interview)
Imagine you have a call center with three levels of employees: fresher, technical lead (TL), and product manager (PM). ...
12
votes
1answer
317 views
Is splitting to small classes good?
I have materials:
class Material {...};
class ConcreteMaterialA : public Material {...};
class ConcreteMaterialB : public Material {...};
I want it to have a ...
10
votes
11answers
868 views
Design dilemma: extensibility vs simplicity
Here is my problem abstracted to Bird classes. I know that number of Birds will increase on the future and new behaviors might ...
10
votes
1answer
82 views
DataLayer Interfaces Genericized
I have some concerns on my refactoring for the data layer in my current Project. Just for a small info, I am currently building a CRM as "training JEE application". But enough of talk, let's talk ...
8
votes
3answers
322 views
Why would I want to always have to explicitly call a “base” method if I just want to use base functionality?
I recently worked with an architect who structured his base class like this:
...
7
votes
6answers
581 views
Fluent interface and polymorphism
EDIT: For further improvements see the related question: Variadic templates and pointers to member functions to achieve a named-parameters interface in C++
I would like to improve the interfaces of ...
7
votes
2answers
1k views
Dispose pattern - DisposableObject
I am trying to make an universal implementation of IDisposable (as a base class):
...
7
votes
1answer
129 views
Moving method from derived class to base
I've some classes (Derived1, Derived2, etc.) derived from class Base. All of derived classes ...
7
votes
0answers
107 views
Out of order class resequencer
I got bored recently and wrote a tool to re-order out of order classes in Python files. This can occur with some auto-generation code tools for databases and the like; these files can sometimes be ...
6
votes
4answers
403 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
134 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 ...
6
votes
2answers
221 views
Class for printing class hierarchy as text
I'm coding a little class hierarchy printing tool for easy show hierarchies of java classes.
This is my current code:
...
5
votes
3answers
55 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 ...
5
votes
3answers
115 views
Object inheritance
I have written some example code to test object inheritance, but I'm not sure if it's really the best way for an object to inherit another's functions (like Java's ...
5
votes
2answers
72 views
Avoiding casts in abstract types
I asked this question on Stack Overflow and in the comments someone had this to say.
In a proper design, you should almost never have to do a dynamic_cast, even if it's hidden inside some nice ...
5
votes
1answer
275 views
Generic pipe and filters
I made a template pipe and filters to replace an old pipe and filters implementation that used inheritance and had a very heavy base class.
...
5
votes
2answers
82 views
Least amount of HTML and CSS to create a bottom border for every section?
I am doing a redesign and have some previously existing content in HTML that is similar to
...
5
votes
2answers
67 views
When should I actually derive from my interface?
Context:
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:
...
5
votes
1answer
42 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 ...
5
votes
1answer
84 views
Improving XNA's default project template
I hope this isn't getting annoying, but I've asked a lot of questions about improving my game lately:
How can I improve my game project design?
Using the observer pattern with collision detection
Is ...
5
votes
1answer
113 views
Prototype inheritance with Knockout observables
I'm trying to write a JavaScript library to allow inheritance with knockout.
The fundamental problem when implementing inheritance in Knockout is that each Knockout observable is its own instance, ...
4
votes
1answer
97 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....
...
4
votes
1answer
570 views
Cross-browser DOMTokenList object and wrapper function. Failures and improvements?
I have been looking for a Cross-browser solution for DOMTokenList and element.classList. I wasn't able to find much for ...
4
votes
1answer
47 views
dnaof() - inheritance made easy, my own make inheritance tool
https://github.com/exebook/dnaof
I created this simple inheritance tool for JavaScript, could any one with deep knowledge in JavaScript prototyped inheritance review it?
Here is the library itself:
...
4
votes
0answers
87 views
Is this pass-by-reference of a shared_ptr correct?
I'm writing a scene graph library in C++ and I'm currently designing the parent-child relations. I decided to use shared pointers for parent-to-child-relations and weak pointers for child-to-parent ...
4
votes
0answers
44 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 ...
3
votes
2answers
91 views
Using properties efficiently in inheritance
I have a class called Mailer which has some properties like this
...
3
votes
2answers
319 views
Classes and variables in PHP
First of all, I'm trying to learn OOP PHP, so any advise will be great.
My idea is to create some kind of MVC Framework CMS kind of thing, just to learn OOP PHP and MVC well.
Let's say that I've got ...
3
votes
2answers
86 views
Is my code overdesigned? Does it rely too heavily on interfaces?
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 ...
3
votes
2answers
164 views
Trying to use classes in my python code. Not sure if being done correctly
The point of my code is to:
Read in the observed data from the a catalog of stars (whitespace separated table).
Do some unit conversions on the observed data (math stuff).
Apply an interstellar ...
3
votes
1answer
442 views
Case class design in Scala
In the Java world while writing the data access layer (for CRUD) and the model layer, I have done something like this:
...
3
votes
3answers
349 views
Creating students and instructors
It's simple. Person is a superclass. Student and Instructor are its subclasses. The program ...
3
votes
1answer
8 views
Better solution than inheritance with “busy” __init__
The goal was to create a node object with input and output ports for a data flow system. I approached the problem using inheritance as I couldn't think in an easy way to do it with composition.
My ...
3
votes
1answer
263 views
A parent class, a singleton subclass, and a subclass uses a builder [closed]
There are three classes and an interface. The parent class is called MobileSignal. It contains info about mobile signal. E.g., CID, LAC, device ID, MCC, user ...
3
votes
1answer
66 views
Get Ancestor Class Name that Defines CONST in PHP?
I have a class hierarchy in PHP and in some of the parent classes I have defined a constant, let's assume that constant is called TYPE for my example.
I want to ...
3
votes
2answers
1k views
Please check my improvement on John Resig's Simple JavaScript Inheritance
I've recently read this article, and I agree that the new keyword is not good practice.
Thus, I've made an improvement on John Resig's Simple JavaScript ...
3
votes
2answers
106 views
How would you improve this object model design to get around Covariance Issues with ObjectModel.Collection<T>?
Consider the following simple relationship.
Code
...
3
votes
0answers
29 views
Many interfaces and lots of inheritance vs few interfaces and less inheritance?
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
3answers
87 views
Color vision checkup
I have this old project I wrote years ago and it's all classes and methods all over the place. I am trying to learn/understand how I can apply a more OOP principle. It is very large and can't paste ...
2
votes
3answers
69 views
2
votes
1answer
64 views
Can this architecture of base + derived classes be coded more efficient? [closed]
I've got some architecture in my code similar to this. It is about the Construct method in the base class in the example below. This method contains the logic for constructing a building, which is the ...
2
votes
2answers
2k views
Good implementation of Equals and GetHashCode for base class
Is this a good implementation for Equals and GetHashCode for a base class in C#:
...
2
votes
3answers
74 views
Raising error if method not overridden by sub-class
Background
I have a base (only 2 classes inherit from it, and only from it) abstract (meaning I don't want it to be used directly) class that implements some common functionality.
Some of it depends ...
2
votes
2answers
968 views
My self-study inheritance and sub-class exercise.
I'm self-studying Java and have a question about one of the end-of-chapter exercises. The chapter focus is on inheritance and the book hasn't officially introduced polymorphism so I'm trying to stay ...
2
votes
2answers
280 views
“fake” covariance in PHP type-hinting
Here's the situation: I've got several distinct objects, each with their own responsability and (therefore) each their own dependencies. As this is code that will be implemented in 2 existing ...
2
votes
1answer
39 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 ...
2
votes
3answers
175 views
Flaws in this Design?
I need to find the flaws in this design. So far the only ones i can think of are:
No use of generics
the class Concept uses a parametrized constructor, which means every sub class would need to pass ...
2
votes
1answer
235 views
Instantiation/Inheritance Helper — Optimization / Pitfalls
For the sake of learning javascript better and getting used to the Google Chrome Extension Api, I'm currently writing a little Chrome Extension.
To keep things simple and being able to make use of ...
2
votes
0answers
12 views
Namespace handling on nodejs and inheritance managing
It should solve the following 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 inheritance ...
2
votes
1answer
31 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:
...