abstract-class

Passing a derived class to a web service method that takes an abstract type

I have a bizarre problem that is doing my head in. I have the following classes defined in a single project: public abstract class AbstractUnitModel { public void executeRemoteModel(){} } //this class also implements a seperate interface, but I dont think that is the issue public class BlastFurnaceUnitModel : AbstractUnitMode...

Basic question on refactoring into a abstract class

This may be a beginner question but is there a standard way to refactor the duplication of the Wheel property into the abstract class yet still maintain the explicit cast to the Part type. Let’s assume we have to prevent a FastCarWheel from being put on a SlowCar, and that there are many properties just like this one. abstract class Car...

Interface + Extension (mixin) vs Base Class

Is an interface + extension methods (mixin) preferable to an abstract class? If your answer is "it depends", what does it depend upon? I see two possible advantages to the interface + extension approach. Interfaces are multiply inheritable and classes are not. You can use extension methods to extend interfaces in a non-breaking way. ...

abstract explicit interface implementation in C#

I have this C# code: abstract class MyList : IEnumerable<T> { public abstract IEnumerator<T> GetEnumerator(); //abstract IEnumerator IEnumerable.GetEnumerator(); } As is, I get: 'Type' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. remove the comment and I get: The modifier 'a...

Abstract class, constructors and Co. C#

Well, I'm trying to reuse a portion of C# code. It's an abstract class with UDP server, which can be seen here: http://clutch-inc.com/blog/?p=4 I've created a derived class like this: public class TheServer : UDPServer { protected override void PacketReceived(UDPPacketBuffer buffer) { } protected o...

Why do we need constructors and private members in the abstract class?

Why do we need constructors and private members in the abstract class? It is not like we are ever going to create an instance of that class. ...

Cloning an abstract object in java

I am trying to grab an object from an array list and copy it to another array list. as per a request public abstract class codeType{ stuff } public class drawOval extends codeType{ } main{ arrayList<codeType> a arrayList<codeType> b a.add(new drawOval(stuff)) a.add(new drawOval(other Stuff)) b.add(a.get(0)...

Is it possible to have specialized parameters in overridden methods?

Let's say I have an abstract parent class called "shape", and that there are multiple subclasses (triangle, square, circle... ). I want to define an abstract method in the parent "shape" class which all subclasses must implement, let's call it "draw". So all shape subclasses must provide the "draw()" method. But, the draw method takes a ...

C# syntax for declaring a variable of an abstract generic type

I have a class defined as follows; public abstract class Repository<TEntity, TDataContext> : DisposableBaseClass where TEntity : class where TDataContext : DataContext, new() {...contains Linq to SQL related functionality In the concrete sub-class I define the types as so; public class ConcreteRepo : Repository<LSTableClass, LS...

Pimpl idiom vs Pure virtual class interface

I was wondering what would make a programmer to choose either Pimpl idiom or pure virtual class and inheritance. I understand that pimpl idiom comes with one explicit extra indirection for each public method and the object creation overhead. The Pure virtual class in the other hand comes with implicit indirection(vtable) for the inheri...

Abstract class + mixin + multiple inheritance in python

So, I think the code probably explains what I'm trying to do better than I can in words, so here goes: import abc class foo(object): __metaclass__ = abc.ABCMeta @abc.abstractmethod def bar(self): pass class bar_for_foo_mixin(object): def bar(self): print "This should satisfy the abstract method require...

Avoid Deadlock using Non-virtual Public Interface and Scoped Locks in C++

I've run into a problem which seems troubling to me. It seems I've found a situation that's easy enough to work-around, but that could lead to problems if a) I have a lapse in concentration while programming or b) somebody else starts implementing my interfaces and doesn't know how to handle this situation. Here's my basic setup: I've...

How to use integrated unit testing in VS2008 to test abstract class

I can't find any info on whether it can do this. I have a couple of protected methods inside the abstract class and want to test these. I don't want to inherit from the class and test its implementation (besides thats technically not strictly unit testing, also VS2008 won't let you test inherited methods). I would like to solve this p...

Should an abstract class have a serialVersionUID

In java, if a class implements Serializable but is abstract, should it have a serialVersionUID long declared, or do the subclasses only require that? In this case it is indeed the intention that all the sub classes deal with serialization as the purpose of the type is to be used in RMI calls. ...

When is it OK for an abstract base class to have (non-static) data members?

I guess the question title sums it up. Is there a time when it would be considered good design for an ABC to have data members? I have been wondering if there is a situation where this is OK. The only ones I can come up with all are static, and even then it's kind of a stretch. ...

Abstract classes vs. interfaces vs. mixins

Could someone please explain to me the differences between abstract classes, interfaces, and mixins? I've used each before in my code but I don't know the technical differences. (And yes, I've searched, but everything I found was either too technical or otherwise unhelpful.) ...

Where to put unique adjustments when using abstract base class

Hi, I´m having some trouble deciding in which way to go... I've got this application which consists of one base project, and one project for the application, the application project contains code targeting a specific system, system application. The base project is an abstract class containing abstract methods which each system speci...

Can Flex 3 handle abstract types in a web service?

UPDATE: It looks like this same question has gone unanswered on the Adobe forums. I have a C# web service exposed via WCF. Some of the exposed operations take/return abstract types. When I use the client stubs generated by Flex Builder 3, I construct the derived types and pass them as parameters to the web service call. This all appears...

Web services - XmlInclude in a derived class instead of a base class?

Hi, I am using an abstract class as a parameter in a web service call. Currently, I am including an XmlInclude of a derived class in the base class, like so: [XmlInclude(typeof(DerivedClass))] public abstract class BaseClass { } However, I'd rather not include all of the derived types in the base class. In http://www.pluralsight...

What are some real-world examples of abstract new/virtual/override/abstract keywords?

I'm moving from PHP to C#. In PHP it was simple and straightforward to use abstract classes to create a "cascading override" pattern, basically "the base class method will take care of it unless the inheriting class has a method with the same signature". In C#, however, I just spent about 20 minutes trying out various combinations of t...