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
1answer
445 views

Making TypeNameHandling in json.net more convenient

Handling abstract types in json.net can be sometimes challenging because it requires a very long and complex syntax like: ...
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 ...
2
votes
1answer
113 views

Growing potatoes in delayed sequences

In order to grow potatoes I'm implementing the retry pattern. If I fail to grow them, I'd like to try it again later. The first part I've implemented is a collection of delay generators. Their base ...
14
votes
5answers
3k views

Mini RPG equipment code

what do you think about this code? It's upgraded version of: Classes representing items in an RPG game ...
6
votes
2answers
526 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 ...
11
votes
5answers
2k views

A simple program with trains and inheritance

Here it is my program. I'm especially worried about the main because I know that one must be careful while instancing vectors of "inherited" objects. The code I have works fine (as far as I can see) ...
8
votes
1answer
508 views

Creating Inheritance hierarchy using function constructor

Problem statement You need to create the Animal base class having four fields: a. name b. ...
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 ...
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 ...
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 ...
8
votes
1answer
15k views

Calculate area and perimeter for shapes: polygon, circle, rectangle and triangle

This is my project on inheritance and polymorphism. I have the main file from my teacher and built the project base on it. My base class is Shape. ...
7
votes
1answer
175 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. ...
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 ...
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
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 ...
5
votes
3answers
373 views

Inheriting from std::auto_ptr to support deletion of allocated arrays in C++98/C++03

[EDIT: Thanks for your opinions. I think this topic is discussed enough. Since std::auto_ptr is removed from C++17, I decided to drop the idea of inheriting from <...
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 ...
5
votes
1answer
51 views

Class Item: A new Implementation to the qes already asked

This is a follow-up question to this: class-item-answer-to-one-of-the-unsolved-stack-overflow-qes. As per the comments I received from @Ben Steffan, I have re-written the above classes as follows. ...
3
votes
1answer
1k views

Classes representing items in an RPG game

I wrote a little program in C# that contains classes representing Items in RPG game. I wanted to have access to all inherited classes parameters from list contains parent Item class instances, so this ...