0
голосов
3ответов
123 просмотров

Impact analysis on subclass

I was modifying an overridden method of a subclass. In order to determine the impact of the change, I went through all possible scenarios and tested them. The problem is, the "all possible scenarios" are determined by reading business use cases, putting break point to find out when this particul...

5
голосов
6ответов
3272 просмотров

C++: Polymorphic class template

Consider a class Calendar that stores a bunch of Date objects. The calendar is designed to hold a collection of any type of objects that inherit from Date. I thought the best way to do it is to have a class template such as template<typename D> class Calendar{ ... } But it struck me...

28
голосов
4ответов
6348 просмотров

Is Clojure object-oriented at its heart? (Polymorphism in seqs)

Clojure is a functional lisp, reportedly not at all object-oriented, even though it runs on the JVM, a VM designed for an object oriented language. Clojure provides identical interfaces for iterating over lists and vectors by abstracting them to an interface called seq. This is even implemented...

3
голосов
4ответов
3556 просмотров

static method with polymorphism in c++

I have a weird issue using polymorphism. I have a base class that implements a static method. This method must be static for various reasons. The base class also has a pure virtual method run() that gets implemented by all the extended classes. I need to be able to call run() from the static clas...

69
голосов
5ответов
7104 просмотров

Why does this polymorphic C# code print what it does?

I was recently given the following piece of code as a sort-of puzzle to help understand Polymorphism and Inheritance in OOP - C#. // No compiling! public class A { public virtual string GetName() { return "A"; } } public class B:A { public override string GetName...

0
голосов
1ответов
654 просмотров

rails way to transfer polymorphic object through url

how do i pass a polymorphic object to another controller? for example redirecting from messages/1/ to requests/new?object_type=message&object_id=1 or, second example, from files/154/ to requests/new?object_type=file&object_id=154 is redirect_to new_request_path(:object_type => p...

10
голосов
2ответов
8877 просмотров

A pointer to abstract template base class?

I cannot figure this out. I need to have an abstract template base class, which is the following: template <class T> class Dendrite { public: Dendrite() { } virtual ~Dendrite() { } virtual void Get(std::vector<T> &o) ...

1
голосов
4ответов
878 просмотров

C++ Collection of instances implementing a pure virtual class

I am working in cross platform C++, and have some classes defined like so: (heavily simplified for this example) class ExampleBase { public: ExampleBase( int blah ) : blah_test(blah) { } virtual void DoSomething( ) = 0; private: int blah_test; }; class ExampleImplementer : public E...

1
голосов
1ответов
438 просмотров

Adding properties to an existing object retrieved using SubSonic

I think this is more of a polymorphism question but it applies to SubSonic table objects... Here's the thing (and I love this one): TblUser userObj = new TblUser(1); Which fills userObj's properties with all of PK=1's goodies. Now, I'd like to add more properties to the existing user object, ...

19
голосов
4ответов
1978 просмотров

What uses have you found for higher-rank types in Haskell?

Higher rank types look like great fun. From the Haskell wikibook comes this example: foo :: (forall a. a -> a) -> (Char,Bool) foo f = (f 'c', f True) Now we can evaluate foo id without the compiler exploding. This example is quickly followed in the book by the real-world example I have s...

0
голосов
1ответов
350 просмотров

Am I Using A Factory To Promote Polymorphism?

My first question is basically asking for a code-review. Does the code I'm about to provide use a Factory to promote Polymorphism? Its written in PHP. Here are the basic requirements: Pass a long url to a library and return a shortened url. Along with the long url, pass user properties to a...

10
голосов
2ответов
7129 просмотров

Matlab Polymorphism

I've got two new-style MATLAB classes - B & C, both concrete subclasses of an abstract parent, A. A is a subclass of hgsetset (handle class). I'd like to put them in an array in MATLAB, and treat them both as As. They are defined, roughly, as: classdef A <hgsetget methods function ...

2
голосов
2ответов
3294 просмотров

Objective-C protocols mimicking 'virtual-functions' yield compiler warnings?

In Objective-C, I'd like to force derived classes to implement a given interface without providing a default implementation (an implementation in the parent class). I understand that Protocols can be used for this, and I believe I understand how to use Protocols, but I'm apparently missing somet...

4
голосов
1ответов
1064 просмотров

Subclassing and Casting in Objective C

I came across a strange problem today. I created a subclass of UIView and added only 1 method to the template code provided by xcode. @interface FloatView : UIView { } - (void)floatTest:(CGFloat)x; @end - (void)floatTest:(CGFloat)x { NSLog(@"float was %f", x); } Then in my appDelegate I ha...

7
голосов
3ответов
5586 просмотров

Polymorphism & Pointers to arrays

I have a class A: class A { public: virtual double getValue() = 0; } And a class B: class B : public A { public: virtual double getValue() { return 0.0; } } And then in main() I do: A * var; var = new B[100]; std::cout << var[0].getValue(); //This works fine s...

5
голосов
4ответов
1845 просмотров

Determining size of a polymorphic C++ class

Using the sizeof operator, I can determine the size of any type – but how can I dynamically determine the size of a polymorphic class at runtime? For example, I have a pointer to an Animal, and I want to get the size of the actual object it points to, which will be different if it is a Cat or a...

2
голосов
5ответов
1903 просмотров

how can I replace instanceof in this case?

I'm trying to compare compareCriteria. Simple ones like 'between' and 'inArray' or 'greaterThan'. I use polymorphism for these classes. One method they share from the compareCriteria interface is 'matchCompareCriteria'. What I'm trying to avoid is having each class check for the type of compareC...

1
голосов
3ответов
1859 просмотров

refactoring and removing case statements when circling over an enum structure

An enum structure declared in its own class is a member variable to the business logic class. That enum basically represents the state of that other class. Although I have revisited the issue several times, replacing, or getting rid of those case statements proves quite frustrating to me. Sever...

1
голосов
4ответов
1554 просмотров

has_many :through, nested polymorphic relations

Is there a way to directly reference (using rails directly, without resorting to a lot of custom SQL) a relation that is nested behind a polymorphic relation? In the below example, is there a way to define a has_many relation in User that references LayerTwo? I'd like to do (in User) has_many...

5
голосов
3ответов
1394 просмотров

trouble making polymorphism defeat those switch/case statements

Continuing on previous questions (here, and here), I implemented a basic command pattern, created my command classes and coded to an interface, so when any command is used, to call the execute() method. However, I am still finding myself unable to shake those case statements: I am reading each ...

2
голосов
3ответов
3880 просмотров

Error calling function and passing a reference-to-pointer with a derived type

Can somebody explain why the following code is not valid? Is it because the offset for the variable named d is different than the variable named b? class Base { public: int foo; }; class Derived : public Base { public: int bar; }; int DoSomething( Base*& b ) { return b->foo; } Base* b ...

2
голосов
2ответов
2302 просмотров

Java Webservice and Polymorphism

Let's say i have the following strucutre public class Mammal { @WebMethod public ArrayList<Mammal> getAll(){ return null; } @WebMethod public String speak(){ return "Unable to speak"; } @WebMethod public Mammal me(){ return this; } } @WebService public class Huma...

1
голосов
1ответов
313 просмотров

Constructor Polymorphism Help

I have a UserControl that has a BaseClass object as a public member. Right now I'm doing the following to discern between which type of object I need to instantiate: Public WithEvents theForm As OrderForm Protected Sub Page_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles ...

7
голосов
6ответов
3238 просмотров

C# numeric base class

I want to write a C# method that can accept any number. Something like: public static T Sum(T a, T b) where T : number { // (not real code) return a + b; } But I don't see a "number" base class in C#, as exists in most other languages I've used. The numeric value types are IComparable, ...

2
голосов
6ответов
841 просмотров

Should we need to differentiate between Interface class and abstract class, in terms of naming convention?

Is that important to differentiate between Abstract class and interface class? Abstract class is merely an interface class, with some concrete methods. If the abstract class shares the same prefix "I" with Interface class, we can easily upgrade our interface class to abstract class, by introduc...

1
голосов
4ответов
1896 просмотров

Access member variables of derived class object pointed to by a pointer to its base class

I have one base class and two classes derived from it. I have several virtual functions in the base class so I create a pointer to the base class and use this pointer to access these methods. Now I want to access member variable of derived class (this variable is not present in the base class) u...

2
голосов
4ответов
1797 просмотров

Polymorphism in VB.NET via Late Binding disallows With Events, workaround?

I'm working on developing an application that talks to a family of USB sensors. I've created a basic implementation that utilizes a class called Sensor. The class contains events and methods that allow for interaction with the sensor (there is also a threaded task processor involved but I'll go w...

0
голосов
1ответов
707 просмотров

C# Inheritance, accessing child members with base functions?

I have a class which inherits from another and I want to make use of one of the base class functions...but I am running into a problem where calling the base function does not return the member variable from the inherited class as I had hoped. To illustrate my problem, I have created a simplifie...

2
голосов
7ответов
1894 просмотров

What is the best way to differentiate between derived classes of a base class?

I have base class BaseClass and derived classes DerivedA, DerivedB, and DerivedC that all inherit BaseClass. I have another class, ExternalClass with a method that accepts a parameter of type BaseClass, but is actually passed a derived class. What is the best way to differentiate between these c...

22
голосов
3ответов
26337 просмотров

Correct Implementation of Virtual Functions in PHP?

at my working place (php only) we have a base class for database abstraction. When you want to add a new database table to the base layer, you have to create a subclass of this base class and override some methods to define individual behaviour for using this table. The normal behaviour should st...