I wrote this yesterday, in a class Foo inheriting from Bar:
public override void AddItem(double a, int b)
{
//Code smell?
throw new NotImplementedException("This method not usable for Foo items");
}
Wondered subsequently if this is a possible indication that I should be using a Bar, rather than inheriting from it.
What other...
How does inheritance of NSNotificationCenter observers work? I have a parent class that several other classes end up subclassing. The parent class registers itself as an observer for a specific notification. I was under the impression that children would also be registered as observers as long as you invoke the super method where the reg...
Hi, I was wondering if there's a language feature in Java in which methods of a superclass would be invisible for members of a subclass:
public class Subclass extends protected Superclass
or something. I'll give an example.
Here is your superclass.
public class A{
public String getA(){...}
public String getB(){...}
publ...
Hello!
I'm getting this error when dealing with a number of classes including each other:
error: expected class-name before '{' token
I see what is going on, but I do not know how to properly correct it. Here is an abstracted version of the code:
A.h
#ifndef A_H_
#define A_H_
#include "K.h"
class A
{
public:
A();
};
#...
I need to write handlers for several different case types (in Python). The interface for all this types are the same, but the handling logic is different.
One option would be defining a common class that receives the particular handler type as one of the __init__ parameters:
class Handler:
def __init__ (self, handlerType):
...
Help,
I have this class
var jMath = {
pi2: Math.PI,
foo: function() {
return this.pi2;
}
}
I want to make the pi2 constant and i want jMath to inherit from Math object. How do I do that?
...
Duplicate
Interface vs Base class
With C#, when to use Interfaces and when to use Abstract Classes, what can be the deciding factor.
...
I can do
public class MyGenericClass : DL
//but i cannot do
public class MyGenericClass <T> : T
How would i do the second? if i cannot do that, how can i do something like
public class MyGenericClass <T>
{
T obj;
//have all MyGenericClass.XYZ call obj.XYZ
}
...
Hi,
The topic of how C# virtual and override mechanism works internally has been discussed to death amongst the programmers... but after half an hour on google, I cannot find an answer to the following question (see below):
Using a simple code:
public class BaseClass
{
public virtual SayNo() { return "NO!!!"; }
}
public class Seco...
Hi, now i'm hoping the following is possible although I'm not entirely certain it is so here goes...
Below is the setup of what I'm hoping is possible (in VB.net, feel free to answer in C# and I should be able to work it out):
Public Class A
Private _name As String
Private _s As SearchA
Public Property Name() As String
...
I'm creating an abstract class that can be inherited in a partial class of a LINQ to SQL class. The LINQ to SQL class contains a bunch of built-in partial methods. Is there a way that I can implement one or more of the partial methods in the abstract class? I know that partial methods can only be contained within partial classes or struc...
I have a base class that contains the following events:
public event EventHandler Loading;
public event EventHandler Finished;
In a class that inherits from this base class I try to raise the event:
this.Loading(this, new EventHandler()); // All we care about is which object is loading.
I receive the following error:
The event 'Ba...
I'm using a library that generates a bunch of classes for me.
These classes all inherit from a common base class but that base class doesn't define a couple methods that are common to all subclasses.
For example:
SubClassA : BaseClass{
void Add(ItemA item) {...}
ItemA CreateNewItem() {...}
}
SubClassB: BaseClass{
void Add(ItemB...
While designing my objects I find composition to be a better choice from the perspective of testability. The reason being, I can mock parts of the composition structure if I need to, while running unit tests. This is not possible if I have an inheritance hierarchy.
I would like to know if others have also found this to be a reason to p...
C# code: Resharper suggests changing the accessibility of a public constructor in an abstract class to protected, but it does not state the rationale behind this.
Can you shed some light?
...
In the below mockup, how do I find out, if I am an instance of FooDAL or WeeDAL from within the method DoMagix()?
Public MustInherit Class DataAccessClass
Public Sub DoMagix()
'** LOOK AT ME!!! **
'Who am I? Why am I here? Where am I going?
'** /LOOK AT ME!!! **
End Sub
End Class
Public Class FooDAL
...
Static inheritance works just like instance inheritance. Except you are not allowed to make static methods virtual or abstract.
class Program {
static void Main(string[] args) {
TestBase.TargetMethod();
TestChild.TargetMethod();
TestBase.Operation();
TestChild.Operation();
}
}
class TestBase {
...
Hello, I am trying to extend the Bitmap class so that I can apply my own effects to an image. When I use this code:
namespace ImageEditor
{
public class Effects : System.Drawing.Bitmap
{
public void toBlackAndWhite()
{
System.Drawing.Bitmap image = (Bitmap)this;
AForge.Imaging.Filters.Gra...
Hi All,
I've got an object, which I'll call MyObject. It's a class that controls a particular data row.
I've then got a collection class, called MyObjectCollection:
public class MyObjectCollection : List<MyObject> {}
Why can I not do the following:
List<MyObject> list = this.DoSomethingHere();
MyObjectCollection collection = (MyObj...
I have a class, Order, which I persist to a database using NHibernate. There is a folder futher down in the web application that contains an object that inherits from Order, for our purposes, we can call it CustomOrder. I use CustomOrder to place a few properties onto the Order object for UI purposes. The properties don't actually hav...