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 something...
I have defined class Parent, and ...
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 A's. They are defined, roughly, as:
classdef A <hgsetget
methods
function foo(this)
%does some common stuff, then
...
Hello! 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
attempt to locate the users specifi...
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, for example, an ArrayList property of say,...
Hello,
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 ExampleBase
{
public:
ExampleIm...
Dears,
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::vect...
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()
{
return "B";
}
}
...
hi,
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 class.
The problem, of course, is that th...
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 internally using a Java interface called ...
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 that D can now in fact be any class.
My questio...
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 particular overridden method is being hit instead ...
it works when :
list<ItemFixed> XYZ::List()
{
list<Item> items = _Browser->GetMusic();
list<ItemFixed> retItems = _Converter->Convert (items);
return retItems;
}
but not :
list<ItemFixed> XYZ::List()
{
return _Converter->Convert (_Browser->GetMusic());
}
Any suggestions?
thanks
...
Heres the code I've made up so far. Its fully functional and the only gripe I have with it is that my output for Weekly and Annual pay is always weekly...I'm at a loss as to how to get this from within either toString method.
public class PolyEmployees {
public static void main(String[] args) {
Employee [] myEmployees = {
...
I have an abstract base class (Comparable) with Date and Time virtually inheriting from it and a DateTime class v-inheriting from Date and Time.
My problem is this:
I was tasked with dynamically allocating an array of Comparables.
Comparable ** compArray;
compArray = new Comparable *[n]; // where n is user specified number of elements
...
I have the following code:
class Visitor
{
internal virtual void Visit(Node n) { }
}
class VisitorSpecial : Visitor
{
internal new void Visit(Node n) { }
}
class Base
{
internal virtual void Accept(Visitor v) { }
internal virtual void Accept(VisitorSpecial v) { }
}
class Node : Base
{
internal override void Acc...
Storing objects in heterogeneous vector with stack-allocated objects
Hello,
Say I have an abstract class CA, derived into CA1, CA2, and maybe others.
I want to put objects of these derived types into a vector, that I embbed into a class CB. To get polymorphism right, I need to store a vector of pointers:
class CB
{
std::vector <C...
I'm working on a somewhat complex mathematical code, written in C++. I'm using (templated) tree structures for adaptive function representation. Due to some mathematical properties I end up in a situation where I need to change from one type of node to another. This needs to happen transparently and with minimal overhead, both in terms o...
Here's what I want to do:
XmlWriter writer = XmlWriter.Create(
(string.IsNullOrEmpty(outfile) ? Console.Out : outfile)
);
This does not compile, however, giving the error "Type of conditional expression cannot be determined because there is no implicit conversion between 'System.IO.TextWriter' and 'string'". The above code is a s...
Consider the code :
#include <stdio.h>
class Base {
public:
virtual void gogo(int a){
printf(" Base :: gogo (int) \n");
};
virtual void gogo(int* a){
printf(" Base :: gogo (int*) \n");
};
};
class Derived : public Base{
public:
virtual void gogo(int* a){
printf(" Derived :: gogo (int*) \n...
Once and for all I want to clearify this somewhat subjective and argumentative area of programming.
Multiple inheritnace
In my current working enviornment I have C++ developers and C# developers which come from totaly different worlds and thus have different opinions on programming layout.
Now being a C# and Java developer myself I've...