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
1
vote
1answer
47 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 ...
7
votes
3answers
10k 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 ...
11
votes
1answer
185 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 code!...
8
votes
2answers
5k 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
2k 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
100 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
146 views

Using properties efficiently in inheritance

I have a class called Mailer which has some properties like this ...
3
votes
1answer
63 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: ...
22
votes
5answers
6k 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). ...
10
votes
6answers
3k views

Fluent interface and polymorphism for building a scene with shapes

I would like to improve the interfaces of some polymorphic classes going from positional to named parameters and I came up with the fluent interface. The following is the most clean, compact and ...
5
votes
1answer
254 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
2answers
114 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 ...
6
votes
1answer
725 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 ...
1
vote
1answer
157 views

Subclasses instantiating superclass of class Human

I have a test which looks like this: Create a base class Human Human class needs to have a method ...
2
votes
2answers
262 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. ...
7
votes
1answer
6k 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
366 views

Moving method from derived class to base

I've some classes (Derived1, Derived2, etc.) derived from class Base. All of derived classes ...
6
votes
3answers
191 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 ...
9
votes
3answers
1k 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
156 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 ...
1
vote
1answer
79 views

Initialization of Extended class without too much overhead?

I am getting object of a class AAA from somewhere and I want to add more information in that object. So, I am creating a new class BBB which is derived from AAA. The class BBB has additional field ...
1
vote
1answer
45 views

Parent implementation different to child implementation

I have the following interface: ...
3
votes
1answer
2k views

How to deal with interface inheritance and common properties? [closed]

I'm trying to design a generic caching system that takes keyed items and allows either read-only or read-write access to a cached version of it. The read-only backing interface is: ...
7
votes
2answers
5k views

Dispose pattern - DisposableObject

I am trying to make an universal implementation of IDisposable (as a base class): ...
4
votes
1answer
212 views

Creating a game with rectangular shapes

I'm using Pygame to create a small game with few rectangle shapes. However, I want to learn more about classes, and I'm trying to use them. I'm very new to classes and inheritance, but I want to ...
1
vote
2answers
537 views

Inheritance and forcing methods to be called inside another method [closed]

I've written a text parser that extracts useful information from a given text. Texts are formatted different, so there are different specialized parsers. I've designed them so that they all must ...
4
votes
2answers
3k views

Improving on John Resig's Simple JavaScript Inheritance: avoiding `new`

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 ...
2
votes
1answer
658 views

Understanding OO JavaScript with a simple scenario

Coming from a Java kind of OOP, I miss a lot of things in JavaScript. I am working on a Node.Js project, and I would like to use an OO approach. Looking around and asking in StackOverflow I came up ...
1
vote
1answer
104 views

Please check if these two methods for inheritance and initialization are good or bad

I am new to JavaScript. I know that many inheritance and initialization methods have been written and use some advance features like Object.create: Simple ...
4
votes
3answers
2k 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 ...
4
votes
2answers
360 views

Performing calculations with a catalog of stars

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 ...
7
votes
1answer
175 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 ...
4
votes
1answer
2k 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 ...
1
vote
1answer
5k views

Javascript Nested Classes

Are there any potential issues with the following Javascript code: ...
4
votes
2answers
679 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
13k views

Implementation of Equals and GetHashCode for base class

Is this a good implementation for Equals and GetHashCode for a base class in C#? If it's not good enough, can you suggest ...
-1
votes
3answers
430 views

Design of Concept Class

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 ...
4
votes
3answers
35k views

Very simple events implementation

I've been thinking about implementing events and wrote some abstract code: ...
6
votes
2answers
2k 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. ...
1
vote
1answer
338 views

My take at OOP module/prototyping JavaScript

The last month I've been reading up on how to take my JavaScript code to the next level. I am a Java programmer at heart, so it feels nice when everything is encapsulated in classes/objects, and these ...
5
votes
2answers
95 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 ...
3
votes
2answers
8k 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 ...
-1
votes
1answer
131 views

Should I use inheritance in my case? [closed]

I have 2 classes that should run a service when calling their Start method, but before it they should: Copy items to F folder Open S service in remote server if it'...
5
votes
4answers
13k views

Understanding interface with animal classes

I made this small program to demonstrate to myself an example of interface. I wanted to confirm whether it is correct and if there is anything more I should know about interfaces other than the ...
1
vote
1answer
104 views

Inheritance selfmade or reinventing wheel

Background I like to code JavaScript in a typical style with "classes" and inheritance. My goal was to create an easy way to make inheritance available and keep classes that inherits from others ...
1
vote
2answers
671 views

Using a dependency container to load a parent/child class

In PHP, I have a parent/child class and am using dependency container to load them. I am trying to use the same database connection on all of them without duplicating the object. I used ...
2
votes
1answer
286 views

Instantiation/Inheritance Helper

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 ...
3
votes
2answers
235 views

How would you improve this object model design to get around Covariance Issues with ObjectModel.Collection<T>?

Consider the following simple relationship. Code ...
1
vote
1answer
254 views

Driver-layer from top-level app to hardware

I'm attempting to implement driver-layer (shared library) from top-level app to hardware. In the first, I extracted interface functions, which further will be called from "extern "C" SHARED" wrappers ...
3
votes
3answers
2k views

Creating students and instructors

It's simple. Person is a superclass. Student and Instructor are its subclasses. The program ...