abstract-class

LinqToSql - mapping exception when using abstract base classes

Problem: I would like to share code between multiple assemblies. This shared code will need to work with LinqToSql-mapped classes. I've encountered the same issue found here, but I've also found a work-around that I find troubling (I'm not going so far as to say "bug"). All the following code can be downloaded in this solution. Given...

COM-like interfaces warn about non virtual destructor

Is there a way to tell gcc that the abstract class it's compiling does not need a virtual destructor (like COM-objects never have)? For example nsISupports always complains about the missing virtual destructor. Turning off the warning would not help as I may have non-COM-like classes, where I want this warning. So __attribute__((com_int...

How can I emulate multiple-inheritance and use reflection to optimize this code?

I've got a WPF application where PageItems are model objects. My main ViewModel has an ObservableCollection of PageItemViewModels, each one building itself from its matching PageItem model object. Each PageItemViewModel inherits from the abstract class BaseViewModel in order to get the INotifyPropertyChanged functionality. Each PageIt...

C# inheritance

Let's say I have the following code: interface ISomeInterface { void DoSomething(); void A(); void B(); } public abstract class ASomeAbstractImpl : ISomeInterface { public abstract void A(); public abstract void B(); public void DoSomething() { // code here } } public class SomeImpl : ASomeA...

Creating an abstract class in Objective C

I'm originally a Java programmer who now works with Objective-C. I'd like to create an abstract class but that doesn't appear to be possible in Objective-C. Is this possible? If not, how close to an abstract class can I get in Objective-C? ...

Which design option is better to use in coding a framework?

I'm coding up a framework (in Java, but question is generic) in which I will provide a set of interfaces for clients to implement. The functions in the framework are going to rely on how the implementation classes will be constructued, that is, thay depend on those implementations to provide other instances of interfaces. For example I ...

What are the benefits to using a partial class as opposed to an abstract one?

I have been reading Programming Microsoft® Visual C#® 2008: The Language to get a better understanding of C# and what can be done with it. I came across partial classes which I had already encountered from ASP.Net's Page class. To me it seems that you can do what partial classes do with an abstract class and an overridden one. Obviously...

Is Reflection in a base class a bad design idea?

In general reflection in a base class can be put to some good and useful ends, but I have a case here where I'm between a rock and a hard place... Use Reflection, or expose public Factory classes when they really should be private semantically speaking (ie. not just anyone should be able to use them). I suppose some code is in order here...

Protected Constructors and MustInherit/ Abstract class

What is the difference between a class with protected constructors and a class marked as MustInherit? (I'm programming in VB.Net but it probably equally applies to c#). The reason I ask is because I have an abstract class that I want to convert the constructors to shared/static methods. (To add some constraints). I can't do this becaus...

Using Mockito to test abstract classes

I'd like to test an abstract class. Sure, I can manually write a mock that inherits from the class. Can I do this using a mocking framework (I'm using Mockito) instead of hand-crafting my mock? How? ...

Any tips on avoiding code Duplication on this abstraction?

Hi, So I'm building an App using the Entity Framework on top of SQL Compact Edition. I didn't like the idea of using the Entites as my business objects so I've been building a layer (I've called it ObjectModel layer, prob not the best terminology) in-between that will take my plain objects, use them to populate and save the entities. And...

Generic Types vs Abstract class/Interfaces

Suppose we are creating a generic control in .NET. E.g. a tree. I don't understand why people use this generic type definition Control<T> when in Object Oriented Programming I can use an abstract class or an interface: Control<IItem> or Control<BaseClass> So the only thing to do is that, their types must derive from that base clas...

Need help understanding abstract classes that implement an interface

Consider the following example. I have an interface MyInterface, and then two abstract classes MyAbstractClass1 and MyAbstractClass2. MyAbstractClass1 implements MyInterface, but MyAbstractClass2 does not. Now I have three concrete classes. MyConcreteClass1 is derived from MyAbstractClass1 but does not implement MyInterface. MyConcr...

How do I make an Action Script 3 class, used in two SWF files, resolve to the same class when one SWF dynamically loads the other?

Background I am developing a highly modular application in pure Action Script 3 (we are using Flex 4 SDK to automate our builds, but all our code must be able to compile directly in Flash CS4 Professional). We have a "framework.swc" file which contains interface definitions which are shared between all our modules, we have a "mainmodul...

Dynamic Casting in C#

Picture the following situation. I have an XML document as follows, <Form> <Control Type="Text" Name="FirstName" /> <Control Type="DateTime" Name="DateOfBirth" /> <Control Type="Text" Name="PlaceOfBirth" /> </Form> I have an abstract class called Control with a single abstract method called Process which takes a single par...

Equivalent of NotImplementedError for fields in Python

In Python 2.x when you want to mark a method as abstract, you can define it like so: class Base: def foo(self): raise NotImplementedError("Subclasses should implement this!") Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way to mark a field as abstract? Or is stating it in the...

Abstract class / method , how to C# --> VB.NET

I am more familiar with VB and the book i bought has C# examples, now i am stuck. How do I implement the following in VB.NET? public abstract class ENTBaseDATA<T> where T : IENTBaseEntity { public abstract List<T> Select(); public abstract T Select(int id); etc....This code already is converted :) } For complete code see Cha...

abstract operator + ?

Hi all. I've got a class : class base { public : base & operator +=(const int value) = 0; // base operator + (const int val) = 0; // HOW DO I DO THIS ? }; And a child class that derives from it class derived : public base { public : derived() : m_val(0) {} derived(const derived & val) : m_val(val.m_val) {} base & operator = (co...

Adding a set accessor to a property in a class that derives from an abstract class with only a get accessor

I have an abstract class, AbsClass that implements an interface, IClass. IClass has a couple properties with only Get accessors. AbsClass implements the properties of IClass as abstract properties to be defined in the classes that derive from AbsClass. So all of the classes that derive from AbsClass will also need to satisfy IClass by ...

Technical reason for using Abstract Classes in C#/Java

According to OOP, Abstract Classes are needed to model those objects that have no existence in the real-world but serves as a base class for several real-world objects. For Example: BankAccount /\ / \ / \ / \ Current Savings Account Account Here BankAccount should be modeled as a...