abstract-class

Java: interface / abstract classes / abstract method

Please help :/ In Java you can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces? Cheers! ...

Why declare an interface as abstract?

What's point of declaring an interface as abstract? Same thing for an interface method. Is there a point to it? eg. public abstract interface Presenter { public abstract void go(final HasWidgets container); } ...

Attribute, interface, or abstract class

I'm wondering what the general recommendation would be (attribute, interface, abstract class, or combination thereof) for the following implementation: /// <summary> /// Loads class specific information into a list for serialization. The class must extend PlugIn. /// The filenames parameter is passed from a FileDialog. /...

Can you cache a virtual function lookup in C++?

Say I have a virtual function call foo() on an abstract base class pointer, mypointer->foo(). When my app starts up, based on the contents of a file, it chooses to instantiate a particular concrete class and assigns mypointer to that instance. For the rest of the app's life, mypointer will always point to objects of that concrete type. I...

How to force a derived class to include certain properties with default value

I have a class structure for a role playing game which looks like this... public abstract class Item { public abstract string Name { get; set; } } public abstract class Armor : Item { public override string Name { get; set; } } public class Helmet : Armor { public override string Name { get; set; } } Basically, I am trying ...

Why can't we declare a std::vector<AbstractClass> ?

Having spent quite some time developping in C#, I noticed that if you declare an abstract class for the purpose of using it as an interface you cannot instantiate a vector of this abstract class to store instances of the children classes. #pragma once #include <iostream> #include <vector> using namespace std; class IFunnyInterface { p...

Why seems any kind of abstraction to be solved with interfaces instead of abstract classes?

Heyho, There´s a question in my mind for some time now, which hopefully can be cleared quickly by some of you: I am a big fan of MVC, ASP.Net Mvc in my case. What I have noticed is the hype about interfaces. Every video, tutorial and book seems to solve any kind of abstraction with interfaces. I have adapted these patterns, understoo...

Java - Can you access an Enum declared in Subclass from Super class?

I was hoping to declare in Enum type in a subclass and then access it from the super class. This is what I came up with, but it does not work: class Subclass { enum Pets { CAT, DOG; } Class<Pets> getEnumClass() { return Pets.class; } } class Superclass { // This generates a warning: abstract Class<? extends Enum> ge...

Can class be abstract even if does not have any abstract methods? If yes Whats the use?

Hi I have a doubt regarding HttpServlet class is an abstract class even though there is not any abstract method in the class , all methods are concrete. Can class be abstract even if does not have any abstract methods? If yes Whats the use? Thanks ...

Getting the abstract class type from which a class derives

In .NET using the GetType function returns the concrete class type of the object. The problem is that i don't know what the type is going to be until runtime, but i do know from which abstract class its derives ( I am using abstract factories to create the adequate class). How can i get the actual abstract class type? Is it even possibl...

Is creating a base class for all applications of a particular type good design?

I am trying to write a graphics application in C++. It currently uses OGRE for display, but I'd like it to work with Irrlicht or any other engine, even a custom rendering engine which supports my needs. This is a rather long question, so I'd appreciate help on re-tagging/ cleanup (if necessary). I'll start with a little background. ...

Pure base class needs to be exported from DLL?

I have two DLLs a.dll and b.dll and in each one I have one class AClass and BClass. I would like to have both AClass and BClass inherit and implement the same interface AbsBase which is a pure abstract class. In each class I set up the #defines for __declspec(dllimport) and __declspect(dllexport). When I'm trying to compile I get this: ...

Refactoring abstract class in C#

Sorry if this sounds simple, but I'm looking for some help to improve my code :) So I currently have the following implementation (which I also wrote): public interface IOptimizer { void Optimize(); string OptimizerName { get; } } public abstract AbstractOptimizer : IOptimizer { public void Optimize() { // Gene...

What's the difference between an abstract class, and a class with only protected constructors? (.NET)

What are all the difference between an abstract class, and a class with only protected constructor(s)? They seem to be pretty similar to me, in that you can't instantiate either one. EDIT: How would you create an instance in a derived class, with a base class with a protected constructor? For instance: public class ProtectedConstr...

C# - What should I use, an Interface, Abstract class, or Both?

So, hypothetically, I'm building some sort of real estate application in C#. For each type of property, I'm going to create a class such as ResidentialProperty and CommercialProperty. These two classes as well as all other property classes will share some common properties, such as Id, Title, Description, and Address information. What I...

abstract java enum

I write a library that should rely on enums but the actual enum should be defined be the user of my library. In the following example the authorize method requires parameters of the enum type Permission. acl.authorize(userX, Permission.READ, Permission.WRITE) My library should be able to handle arbitrary permissions defined by the ...

How can I represent state of method execution in base class without affecting the implementation in the derived classes?

I'm trying to create an abstract class, defining an abstract method, that is to be derived from other classes that implements some specific behavior in the abstract method. I want the abstract class to contain some kind of state information that represents however the implementation in the derived classes exited without errors, but I wan...

How to tell if a Java class is abstract?

Is there a way programmitcally to tell if a Java class is abstract? (Other than trying to instantiate and catching the error) Thanks! ...

When to use an abstract class with no interface?

Whenever I create an abstract class I tend to create an interface to go along with it and have other code refer to the interface and not the abstract class. Usually when I don't create an interface to start with I regret it (such as having to override all implimented methods to stub the class for unit testing or later down the line new ...

Abstract Class is a good practice?

Hi, I have this scenario: This two clases with this attributes: Table [Id, Name, Parent_Id] Field [Id, Name, Creation_Time, Creation_Date] Is it a good practice to make an Abstract Class to implemet the attributes and properties for ID and NAME so that I save some time writting code; or is it better to rewrite each attribute and pro...