The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
3answers
130 views

Is it bad practice to ignore some parameters while implementing a method of a interface?

Should an interface method implemented by a class always use all parameters? By interface I do not necessarily mean actual interfaces, these could be other (abstract) classes which are extended, too. ...
1
vote
1answer
71 views

What's polymorphic deployment

On pages 136 and 137 in The Clean Coder, Robert C. Martin describes how chips could be independently deployed thanks to a vtable: The solution was pretty simple. Each chip had to be decoupled from ...
4
votes
3answers
136 views

How are typeclasses in functional languages different from interfaces in OO languages?

I'm learning about paradigms of functional languages. So I've read that while Subtype polymorphism is typical for OO languages, Parametric polymorphism is typical for functional languages. But I ...
2
votes
1answer
106 views

Designing generic operations in object oriented languages

I found an interesting quote in SICP that I think is highly relevant in object oriented design: We see that, in general, a type may have more than one subtype. Triangles and quadrilaterals, for ...
3
votes
3answers
438 views

Should conditional logic be always coded via type system where possible?

I have a choice. Option 1: public class Sample { bool IsRelevant { get; set; } } Option 2: public class Sample { } public class RelevantSample : Sample { } Is there a clear well-known rule ...
5
votes
1answer
3k 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 ...
52
votes
17answers
6k views

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

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 ...
7
votes
4answers
2k 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 ...
5
votes
2answers
77 views

Unused function parameters and polymorphism

I had a discussion with a co-worker about interface members having parameters that some implementations don't use. Say I have an interface interface IDoctor { string GetMedicalOpinion(Age age, ...
3
votes
2answers
174 views

Can a function be polymorphic and overloaded?

In Graham Hutton's book "Programming in Haskell", he defines a function to be polymorphic, if its type "contains one or more type variables". He then defines a function to be overloaded, if its type "...
4
votes
2answers
140 views

Understanding polymorphism and interface in Java

I'm reading though some notes. And I'm not understanding the following two statements. Polymorphism means that it is always the class of the actual object at run time that determines which method ...
-1
votes
3answers
182 views

Modularity vs Polymorphism (OOD main concepts)

Booch gives 4 main concepts (principles) of OOD (see his book Object-oriented analysis and design with applications ): Abstraction Encapsulation Modularity Hierarchy Usually we encounter to these ...
-2
votes
1answer
90 views

Static Polymorphism explained

Here is a code I have got from here: class Deletor { public: virtual ~Deletor() {} }; template<typename T> class Base : public Deletor { public: int Run() { return ...
11
votes
3answers
13k 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 ...
1
vote
0answers
38 views

Polymorphically handle result of subtraction

I have an amount class which provides the minus method among others. The result of this operation is of course another amount. The question is how can I handle the three cases according to the signum ...
1
vote
2answers
130 views

C++ Parametric Polymorphism

In the wikipedia article on Parametric Polymorphism, is the following commentary on C++. Can anyone explain what it's referring to when talking about "ad hoc aspects"? (I think it needs a citation)....
1
vote
1answer
179 views

What is the DRY-est factory pattern to instantiate subtypes based on one of their properties' values?

Take the following class hierarchy: Client FacebookClient PinterestClient TwitterClient Each client must define a value for an enum property named ClientType (string property Url in the ...
2
votes
2answers
198 views

Haskell types for functions

I don't understand the answer to this question: Q: Can Haskell find a type for the function selfapply defined by: selfapply f = f f A: The function selfapply is not typeable in the simple ...
0
votes
2answers
106 views

How to simulate method overloading in langs without such feature? [closed]

Langs like Java knows about true method overloading: class Overload { void demo (int a) { System.out.println ("a: " + a); } void demo (int a, int b) { System.out.println ("a and b: " + a +...
10
votes
3answers
351 views

How do you use duck typing in javascript without always checking for properties and methods?

I know javascript uses duck typing and at first I thought this would make polymorphism easy compared to strongly typed languages like C#. But now my functions that take arguments are littered with ...
12
votes
4answers
1k 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 ...
133
votes
5answers
27k views

What exactly makes the Haskell type system so revered (vs say, Java)?

I'm starting to learn Haskell. I'm very new to it, and I am just reading through a couple of the online books to get my head around its basic constructs. One of the 'memes' that people familiar with ...
2
votes
2answers
143 views

How is polymorphism better than two function calls in this example [ATM design]?

So I've finally started reading Designing Object-Oriented Software and my needle is stuck at a small but important point. I understand that the example I'm about to present might appear a bit out of ...
3
votes
1answer
207 views

Why throw a 'must implement this function' exception rather than making the function abstract?

In the Android support libraries here the destroyItem and instantiateItem functions throw an exception if they aren't overriden: 175 throw new UnsupportedOperationException( 176 ...
1
vote
1answer
76 views

What pattern should one use for multiple interpretations of the same data?

I have a set information that I am able to read in as raw data which corresponds to different physical quantities depending on which device provided that information. Every device contains the same ...
3
votes
3answers
567 views

Polymorphic template container: shared_ptr vs reference_wrapper

Assuming we have two classes: class A { ... } class B : public A { ... } Would it be better to write std::deque<shared_ptr<A> > container; or std::deque<reference_wrapper&...
1
vote
1answer
83 views

“Is a” relationship or, in other words Inheritance

Say I define an interface IAnimal which has a pure virtual (abstract) method called eat like this: class IAnimal { virtual void eat(Food*) = 0; }; In the future I inherit form IAnimal and create ...
0
votes
1answer
318 views

How would I handle a set of differing event classes with differing handler interfaces in a single event processor?

I'm working on an event processor framework for a simple game I'm writing, in which multiple types of events are handled in a loop. Since these events carry distinct pieces of data (i.e. one carries a ...
1
vote
1answer
43 views

Creating a specific table for shared columns among other tables (models)?

I'm creating a webapp that has a variety of models: Product, Category, ProductOption, etc. All of these models have a set of shared attributes: name, description, image, etc. There are two options I ...
0
votes
1answer
96 views

Is it good practice to assign an instantiated class to a static property in the same class?

I have code that was written by someone else that goes like this: On a ViewModel: public static ACertainViewModel Default { get; private set; } On the same ViewModel's constructor: public ...
1
vote
1answer
139 views

Accepted Patterns For Base Class with both Static And User-Defined Data Sources

I have a requirement to build a 'base' profile library (in C# - NET 4.5.2) for various different internal (technical) consumers. This profile consists of metadata fields that would be shared by a wide-...
2
votes
1answer
145 views

Implementing a series of independent Actions that are disparate but with common accessibility

I have a requirement to implement a type of AI for a project, the issue is that I am having trouble visualizing how the AI should actually be implemented. Essentially, I want the AI to be as dynamic ...
8
votes
3answers
252 views

Is it bad practice to make a subclass in name only for readability?

I have three sensors in a single package that all need to be calibrated which I will call sens1, sens2, and sens3. The calibration for sens1 and sens2 are identical, but the calibration for sens3 ...
1
vote
1answer
105 views

A little confused with virtual functions

Please see the following code: #include<iostream.h> #include<string.h> class father { char fname[20]; public: father() { strcpy(fname,"eshwarappa"); ...
1
vote
1answer
60 views

Polymorphism on repository interface for local and remote operations

I'm in the process of designing a facade ApiClient class that would abstract some CRUD operations between a local database and a remote one (through a REST web app). Said ApiClient class depends on 2 ...
2
votes
1answer
145 views

Alternatives to #if when polymorphism doesn't seem possible

There are couple of places where #if seems to give you abilities that polymorphism doesn't: Conditionally specifying base class When a section contains code that is not recognised by a compiler on ...
2
votes
1answer
132 views

Should I represent physical accessories of a system as classes in software?

I am redesigning a system comprised of a data-acquisition unit and a lot of different sensors (voltage sensor, angle sensor, pressure sensor, etc.). In the software domain model, there is a base ...
0
votes
1answer
217 views

Protected properties vs protected getters

If I have an abstract Animal class with a $name property and constructor like this: abstract class Animal { protected $name; public function __construct($name) { $this->name = $name; ...
5
votes
1answer
168 views

How to use OO Design to Refactor a Library with Functions that are specific Product-aware

I have a class that acts as a library of functions for various products. To compute its data, the function currently needs to be aware of all product names. Depending on which product calls the ...
1
vote
2answers
5k views

Overriding methods by passing as argument the subclass object where the supertype is expected

I am just learning Java, and am not a practicing programmer. The book I am following says that when overriding a method, the argument types must be the same, but the return types can be ...
0
votes
2answers
272 views

Making subclass more type-specific with accessors

I have a super class: TriggerManager with a subclass TimedTriggerManager. NOTE: I'm working in java TimedTriggerManager only deals with TimedTrigger s, a subclass of Trigger. TriggerManager ...
3
votes
2answers
304 views

Database design for polymorphic data

I have an application that needs to log communications with users over several different mediums: Email, SMS, Voice, Website Announcements, etc.. in a traditional database. I have considered 3 ...
2
votes
6answers
791 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
365 views

Inheritance in imperative programming

My first introduction to programming was Java, which was horrible so I learnt Actionscript3 which was nice... "The point is" OOP was my introduction to programming where by I went on to gain a career ...
1
vote
3answers
406 views

Why static members can't be abstract and don't implement polymorphism? [duplicate]

I'm a Java/C#/PHP developer, through my OOP programming experience I find myself asking the same question: Why static members can't be abstract and don't implement polymorphism especially in ...
0
votes
1answer
196 views

Is not being able to resolve a function call to its declaration a drawback of Polymorphism?

Consider a class that prints an "outline" table for a particular product line. Say you have several, A, B, C, D. The mechanism of the table generation is the same, but the data is different. I ...
17
votes
12answers
4k views

Is method overloading anything more than syntactic sugar? [closed]

Is method overloading a type of polymorphism? To me it seems like simply the differentiation of methods with the same name and different parameters. So stuff(Thing t) and stuff(Thing t, int n) are ...
4
votes
3answers
3k 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 ...
2
votes
2answers
459 views

Is it possible to have Ad-Hoc polymorphism with runtime dispatch?

As I did understand, and as it's described here, ad-hoc polymorphism is limited to compile-time dispatch. That is, if we have a function that expects an argument that belongs to a typeclass, we must ...
0
votes
1answer
322 views

overriding implemented base class methods

I read somewhere that the chain of inheritance breaks when you alter a behavior from derived class. What does "altering a behavior" mean here? Is overriding an already implemented method in base class ...