The tag has no wiki summary.

learn more… | top users | synonyms

44
votes
17answers
4k views

Is OO-programming really as important as hiring companies place it?

I am just finishing my masters degree (in computing) and applying for jobs. I've noticed many companies specifically ask for an understanding of object orientation. Popular interview questions are ...
13
votes
4answers
678 views

Switch vs Polymorphism when dealing with model and view

I can't figure out a better solution to my problem. I have a view controller that presents a list of elements. Those elements are models that can be an instance of B, C, D, etc and inherit from A. So ...
12
votes
6answers
498 views

OO Design, how to model Tonal Harmony?

I have started to write a program in C++ 11 that would analyse chords, scales, and harmony. The biggest problem I am having in my design phase, is that the note 'C' is a note, a type of chord (Cmaj, ...
11
votes
5answers
1k views

Is duck typing a subset of polymorphism

From Polymorphism on WIkipedia In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. From duck ...
9
votes
5answers
611 views

Writing Testable Code vs Avoiding Speculative Generality

I was reading some blog posts this morning, and stumbled across this one: If the only class that ever implements the Customer interface is CustomerImpl, you don't really have polymorphism and ...
8
votes
3answers
483 views

Two components offering the same functionality, required by different dependencies

I'm building an application in PHP, using Zend Framework 1 and Doctrine2 as the ORM layer. All is going well. Now, I happened to notice that both ZF1 and Doctrine2 come with, and rely on, their own ...
7
votes
8answers
1k views

Introducing polymorphism to new programmers

I've been teaching Java to a group of four people for about four months now. Prior to this, they've all had very limited or no other experience programming. We've gotten through basic control ...
7
votes
4answers
452 views

Besides polymorphism, what's compelling about OOP? [duplicate]

When I first came to OOP (at first in Java, and then C++) after years of working in C and VB, it was amazing. The idea of extending existing behaviour and operating generically over things of related ...
7
votes
4answers
531 views

Design pattern for polymorphic behaviour while allowing library separation

Let's say I have a hierarchy of Item classes: Rectangle, Circle, Triangle. I want to be able to draw them, so my first possibility is add a virtual Draw() method to each: class Item { public: ...
6
votes
4answers
4k views

Replacement for instanceof Java?

So I'm fairly new to programming in the real world (outside of academic projects) and have come across lots of posts saying that using instanceof is a bad thing to use to determine what class a ...
5
votes
13answers
876 views

Limitations of Polymorphism in statically typed languages

I program mostly in statically typed languages, like C++ and Java. A common strategy employed in languages like these to handle dealing with collections of objects which are related, but which need ...
5
votes
3answers
685 views

is down-casting always bad?

At my company, we have many different "services" that work in parallel and send messages to each other using a common messaging system. All message objects are derived from a common generic object we ...
5
votes
1answer
436 views

Abstract Factory Method and Polymorphism

Being a PHP programmer for the last couple of years, I'm just starting to get into advanced programming styles and using polymorphic patterns. I was watching a video on polymorphism the other day, and ...
4
votes
3answers
454 views

Novel polymorphism - any reasons for this code?

As part of my work on a legacy C# application I've come across a novel (to me) use of an interface & concrete implementations. I can't think of any reason why you'd do the following, but I'm ...
4
votes
4answers
2k views

What are the benefits of using Polymorphism 'in the real world' - as opposed to not using it? [duplicate]

I understand what Polymorphism is, but since I only ever programmed in Java and 'dived' pretty quickly into OOP, I'm having a hard time understanding exactly what it's benefits are (and I feel the ...
4
votes
2answers
688 views

What is the process of determining which method in a class hierarchy should execute known as?

I thought I understood inheritance and polymorphism, but I was given this question, and I can't, for the life of me, figure out what the proper answer is or what they're trying to get at: The ...
4
votes
2answers
1k views

Is dependency injection by hand a better alternative to composition and polymorphism?

First, I'm an entry level programmer; In fact, I'm finishing an A.S. degree with a final capstone project over the summer. In my new job, when there isn't some project for me to do (they're waiting ...
4
votes
3answers
393 views

Java - Use polymorphism or bounded type parameters

Suppose I have this class hierarchy... public abstract class Animal { public abstract void eat(); public abstract void talk(); } class Dog extends Animal { @Override public void eat() ...
4
votes
2answers
419 views

Reasons behind polymorphism related behaviour in java

I read this code somewhere class Foo { public int a; public Foo() { a = 3; } public void addFive() { a += 5; } public int getA() { ...
4
votes
1answer
1k views

implicit vs explicit interfaces

I think I understand the actual limitations of compile-time polymorphism and run-time polymorphism. But what are the conceptual differences between explicit interfaces (run-time polymorphism. ie ...
4
votes
2answers
266 views

Alternatives to type casting in your domain

In my Domain I have an entity Activity which has a list of ITasks. Each implementation of this task has it's own properties beside the implementation of ITask itself. Now each operation of the ...
3
votes
4answers
229 views

Is there a way to avoid type-checking in this scenario?

I have a class SuperClass with two subclasses SubClassA and SubClassB. I have a method in a different class which takes a SuperClass parameter. The method should do different things depending on the ...
3
votes
3answers
1k views

How to setup the c++ rule of three in a virtual base class

I am trying to create a pure virtual base class (or simulated pure virtual) my goal: User can't create instances of BaseClass. Derived classes have to implement default constructor, copy ...
3
votes
1answer
173 views

Redundancy caused by polymorphism

I have two chat rooms, one has administration behaviour, and one doesn't. I have factored out all of the common code into a base chat room, but the AdministerChatroom behaviour I have pulled out into ...
3
votes
1answer
120 views

Different scoring algorithms for different competition elements

I am creating a scoring system for a competition that is somewhat obscure, but it resembles the Olympics in terms of its high-level structure. Therefore, I will ask my question in terms of an ...
3
votes
2answers
165 views

how to follow python polymorphism standards with math functions

So I am reading up on python in Mark Lutz's wonderful LEARNING PYTHON book. Mark makes a big deal about how part of the python development philosophy is polymorphism and that functions and code should ...
2
votes
3answers
6k views

What is upcasting/downcasting?

When learning about polymorphism you commonly see something like this class Base { int prv_member; virtual void fn(){} } class Derived : Base { int more_data; virtual void fn(){} } What is ...
2
votes
2answers
1k views

Interview question “What is virtual function”

It was funny for me, and I'm interesting the reaction for this question of the community. It was interview for C++/Qt developer, and question was asked "What is virtual function". Not something like ...
2
votes
4answers
497 views

Confusion about inheritance

I know I might get downvoted for this, but I'm really curious. I was taught that inheritance is a very powerful polymorphism tool, but I can't seem to use it well in real cases. So far, I can only ...
2
votes
3answers
179 views

Is 'design with types first' ultimately the same as 'design with interfaces first'?

In Object Oriented Programming, we're taught to think in terms of Polymorphism (the idea that the implementation is decoupled from the interface - and that it makes sense to think of the interface ...
2
votes
5answers
319 views

Classic inheritance problem?

I keep seeing the following pattern when people learn about OOP: Problem: How do I put objects of different but related types into a container? Solution: Inherit from a common base class. New ...
2
votes
2answers
251 views

Does it make sense to use interfaces if you don't have polymorphism?

Suppose I have distinct classes that have the same behavior, which can be represented like this: public interface Behavior { void operationA(); } public class ImplementerA implements Behavior { ...
2
votes
2answers
513 views

Questions about Polymorphism

So I understand the importance of Polymorphism, including how vital it is. But something I don't quite understand is what about the Constructor and any inherited Class the initial Base Class may ...
2
votes
1answer
112 views

Is it bad practice to encapsulate a single operation in a class? [duplicate]

I recently had a back and forth over at StackOverflow about my answer to this question. The question was simple. The author wanted to transform a number into an abbreviated version that appended a K, ...
2
votes
1answer
101 views

What's the right OO way to create a counter/inventory class that works for both differentiated and undifferentiated countables?

You are writing a videogame about trading beans. Red beans, black beans, pinto beans, you name it. As everybody knows all beans are the same. You write the "Inventory" class for a trader in that ...
1
vote
4answers
279 views

When to not use dynamic in C# [on hold]

I'm making a class similar to the following: public class KeyValue { public readonly string key; public readonly object value; } Value could be of any object type as a result of this ...
1
vote
3answers
375 views

Is it bad practice to check object types with an identifying member variable?

Preamble: I am making a simple board game in C++, in which AI characters move around squares on the board. There are different types of squares, each inherited from an abstract class, each with ...
1
vote
4answers
239 views

Combinatorial explosion of interfaces: How many is too many?

I'm a relative newcomer to OOP, and I'm having a bit of trouble creating good designs when it comes to interfaces. Consider a class A with N public methods. There are a number of other classes, B, C, ...
1
vote
1answer
314 views

What does “polyadic” mean in the context of functional programming and type systems?

And how does it (or does not) correspond to "polymorphic"? Occasionally I see this notion like in: Implement and represent polyadic operations. I checked Wiktionary but it only gives a general ...
1
vote
2answers
133 views

Is it an anti-pattern to use void* and enums to enable type-checking?

Say in a game engine, you have Objects that composited of different components. One of these is a RenderComponent which can be either a Mesh, a Sprite or a Light. Now, all these are vastly different ...
1
vote
1answer
581 views

Can the Abstract Factory pattern be considered as a case of polymorphism?

I was looking for a pattern/solution that allows me call a method as a runtime exception in a group of different methods without using Reflection. I've recently become aware of the Abstract Factory ...
1
vote
5answers
171 views

Clarification about Polymorphism / Inheritance

I am trying to better my understanding of polymorphism. Say I have a base class called baseClass with one method called foo() and I have three derived classes called derived1 , derived2 and derived3 ...
1
vote
3answers
116 views

Refactoring - Utility classes behavior under a common interface

I was suggested to put my question here, so I'm doing so ;) I need a common interface which represents some specific behavior: public interface Contract(){ public void methodA(); public void ...
1
vote
1answer
372 views

Readability vs benefits of polymorphism

We are dealing with a lot of CRUD operations in our application. Each database table has one or more corresponding SQLContainer instances to perform various types of operations. All of these ...
1
vote
2answers
118 views

Interface extension

Suppose that I have an input stream interface, which defines a method for reading data. I also have a seekable interface which defines a method for seeking. A natural way of defining a input file is ...
1
vote
1answer
76 views

Ignoring the generic part of a type while an object is being passed

I have a message class that holds the name of a destination, and a generic variable acting as the message payload public class Message<T> { public string Destination public T Payload ...
1
vote
2answers
121 views

Does subtype polymorphism distinguish between inheriting behavior, or inheriting an interface?

To provide some context, I've seen some comments lately that equate inheriting behavior from a supertype, with inheriting a pure interface with no behavior. But there are pretty significant, and ...
1
vote
0answers
11 views

How do multiple levels of inheritance affect virtual function call overhead in C++?

I am considering using a class hierarchy with more than a single level of inheritance, where virtual member functions form a "chain", for example: struct Base { virtual void foo(); }; struct D1 : ...
0
votes
4answers
538 views

Objective-C message passing related queries

I am learning objective-C after having good knowledge of C/C++. I have 2 questions: Are Obj-C message passing and C++ vtable, two different ways of implementing polymorphism or Are they two very ...
0
votes
1answer
115 views

Clean way to use mutable implementation of Immutable interfaces for encapsulation

My code is working on some compost relationship which creates a tree structure, class A has many children of type B, which has many children of type C etc. The lowest level class, call it bar, also ...