I have an interface method
public void Execute(ICommand command);
which needs to pass known subtypes of ICommand to an apropriate Handle(SpecificCommand command) method implementation and do some generic handling of unknown types. I am looking for a universal (i.e. not requiring a giant switch) method of doing so, something similar ...
Ok, bear with me guys and girls as I'm learning. Here's my question.
I can't figure out why I can't override a method from a parent class. Here's the code from the base class (yes, I pilfered the java code from an OOP book and am trying to rewrite it in C#).
using System;
public class MoodyObject
{
protected String getMood()
...
function a () {
return "foo";
}
a.b = function () {
return "bar";
}
function c () { };
c.prototype = a;
var d = new c();
d.b(); // returns "bar"
d(); // throws exception, d is not a function
Is there some way for d to be a function, and yet still inherit properties from a?
...
Whilst trawling through some old code I came across something similar to the following:
class Base
{
public:
virtual int Func();
...
};
class Derived : public Base
{
public:
int Func(); // Missing 'virtual' qualifier
...
};
The code compiles fine (MS VS2008) with no warnings (level 4) and it works as expected - Func i...
All objects in my program inherit from a Container class. The Container class has a virtual BaseNode* getParent() const; method and a virtual void setParent(BaseNode *p); method.
I have a Set class (Set in a tennis match, not a data structure) which has the Match class as it's parent (via setParent()) but since Set inherits from Contai...
Hi All,
Suppose I have this interface
public interface IFoo
{
///<summary>
/// Foo method
///</summary>
void Foo();
///<summary>
/// Bar method
///</summary>
void Bar();
///<summary>
/// Situation normal
///</summary>
void Snafu();
}
And this class
public class Foo : IFoo
{
publi...
In order to represent inheritance how many hbm files are needed?
How do I represent the relationship between base and subclasses in the subclass hbm file?
I want hbm and pojo class of super and sub class.
...
Here's the deal. I have a big class hierarchy and I have this one method that is extended all the way through. The method always has to look at one or two more variable at each new level and these variable depend on the actual class in the hierarchy. What I want to do is check those two extra variables then call the superclass's version ...
I'm trying to find the actual class of a django-model object, when using model-inheritance.
Some code to describe the problem:
class Base(models.model):
def basemethod(self):
...
class Child_1(Base):
pass
class Child_2(Base):
pass
If I create various objects of the two Child classes and the create a queryset con...
Recently I used a class that inherits from a collection instead of having the collection instantiated within the class, is this acceptable or does it create unseen problems further down the road? Examples below for the sake of clarity:
public class Cars : List<aCar>
instead of something like:
public class Cars
{
List<aCar> CarList =...
Is multiple inheritance possible in VB .Net? If so, what is the syntax?
...
I'm still learning ASP.NET and I often see code like this throughout parts of our framework:
Public MustInherit Class DBFileManager(Of F As IDBFile, FC As IDBFileContent, FT As IDBFileThumb)
Can anybody tell me what this means? Much thanks!
...
I have a class hierarchy, this one:
type
TMatrix = class
protected
//...
public
constructor Create(Rows, Cols: Byte);
//...
type
TMinMatrix = class(TMatrix)
private
procedure Allocate;
procedure DeAllocate;
public
constructor Create(Rows, Cols: Byte);
constructor CreateCopy(var t...
This is quite a controversial topic, and before you say "no", is it really, really needed?
I have been programming for about 10 years, and I can't honestly say that I can recall a time where inheritance solved a problem that couldn't be solved another way. On the other hand I can recall many times when I used inheritance, because I...
I am aware of the responses at
Prefer composition over inheritance
and am aware of the merits of composition over inheritance.
But there are cases where inheritance does have a good role to play. It's the incorrect use of inheritance hierarchy that causes all the issues related to reuse.
Take the example of the following controls......
Is it possible to get a list of all descendant classes of a particular class in objective-c?
Something like:
@interface A : NSObject
@end
@interface B : A
@end
@interface C : A
@end
NSArray *descendants = [A allDescendants]; // descendants = [B, C]
...
I'm currently getting through the http://www.cplusplus.com tutorial and I came across this section here: http://www.cplusplus.com/doc/tutorial/inheritance.html that deals with the subject of friend functions and friend classes in C++.
My question is, when When is it prudent to use friendship when creating a program?
The only clue I g...
I've factored out common attributes from two classes into an abstract base class, however I have another model that needs to reference either one of those classes. It's not possible to reference an ABC as it doesn't actually have a database table.
The following example should illustrate my problem:
class Answer(models.Model):
ovram...
Is it possible to inherit from both ViewPage and ViewPage<T>?? Or do I have to implement both. Currently this is what I have for ViewPage. Do i need to repeat myself and do the same for ViewPage<T>??
public class BaseViewPage : ViewPage
{
public bool LoggedIn
{
get
{
if (Vi...