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".
2
votes
2answers
73 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
50 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
284 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.
...
6
votes
3answers
421 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
126 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
64 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
75 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
63 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
104 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 ...
11
votes
2answers
132 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
123 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
25 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 ...
5
votes
2answers
74 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:
...
2
votes
1answer
44 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
63 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 ...
4
votes
0answers
94 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
50 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
0answers
66 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
81 views
4
votes
1answer
102 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....
...
3
votes
2answers
96 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
1answer
10 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 ...
6
votes
4answers
709 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
155 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
44 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 ...
1
vote
2answers
65 views
How to write factory classes or functions in JavaScript? [closed]
I find that in Javascript there are many methods of creating an object so what would be the appropriate approach for constructing an object and why.
...
2
votes
1answer
68 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 ...
1
vote
1answer
36 views
Simple inheritance with functions in subclasses [closed]
It seems like there are many ways implementing inheritance in JavaScript. Which version do you prefer or would you suggest another solution?
The code should run in IE8+ so my first version would not ...
2
votes
0answers
41 views
Forcing base class functions to be used from the base class [closed]
The answer to this question is probably "W-what!? What the !@#$-- Stop!! That's a terrible idea!", but I would like to hear your thoughts...
I have two classes and one inherits from the other.
...
2
votes
3answers
98 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 ...
12
votes
1answer
143 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 ...
6
votes
2answers
295 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
1answer
206 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, ...
2
votes
3answers
88 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 ...
3
votes
2answers
101 views
Using properties efficiently in inheritance
I have a class called Mailer which has some properties like this
...
4
votes
1answer
48 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:
...
15
votes
4answers
813 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). ...
7
votes
6answers
668 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 ...
5
votes
1answer
98 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 ...
2
votes
0answers
38 views
Inheritance and setting up for an API request
I am setting up a class to be used for an API request (with JavaScriptSerializer). I am using it to send a complaint to their ticketing systems.
For example I ...
5
votes
2answers
77 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
96 views
A variant of state pattern + C++ template FSM without state creation/destruction penalty
This is a variant of the solution posted here, without state creation/destruction penalty.
Note that my comment in the original question about the simplification provided by C++11's inherited ...
0
votes
1answer
45 views
Javascript subclasses instantiating superclass (check code)
I have a test which looks like this:
create a base class Human
Human class needs to have a method Talk
the Human class needs to have to descendant class Man and Woman
both Man and Woman should have ...
1
vote
2answers
144 views
Classical inheritance in JavaScript
I've been playing around with inheritance in JavaScript and I'm wondering if there are any drawbacks to this method which tries to emulate classical inheritance from C-based languages.
...
3
votes
1answer
759 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:
...
7
votes
1answer
141 views
Moving method from derived class to base
I've some classes (Derived1, Derived2, etc.) derived from class Base. All of derived classes ...
5
votes
3answers
122 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 ...
8
votes
3answers
334 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:
...
0
votes
1answer
89 views
Coding convention when using differential inheritance
Ever since reading Crockford's "Good Parts" and Johansen's TDD book, I have wanted to use more of the differential inheritance pattern in my coding at work (as in avoiding ...