abstract

A pointer to abstract template base class?

为君一笑 提交于 2019-12-03 02:50:49
I cannot figure this out. I need to have an abstract template base class, which is the following: template <class T> class Dendrite { public: Dendrite() { } virtual ~Dendrite() { } virtual void Get(std::vector<T> &o) = 0; protected: std::vector<T> _data; }; Now, I derive from this which specifies exact usage of Dendrite. Now the problem. How do I create a vector of pointers to the base-class with no specific type, which I want to specify by pushing elements to it later? Something like: class Foo { public: ... private: std::vector<Dendrite *> _inputs; //!< Unfortunately, this doesn't work... //

Abstract and Interface in java [duplicate]

只谈情不闲聊 提交于 2019-12-03 00:55:14
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Interface vs Abstract Class (general OO) When to use abstract class or interface? Can you provided implementations on a abstract class? what's the difference between these two? and when will I know when will I know to use them? 回答1: This pages gives a good comparison: http://download.oracle.com/javase/tutorial/java/IandI/abstract.html . You could have found it with a very quick google search. 回答2: Interface is

The designer must create an instance of…cannot because the type is declared abstract

雨燕双飞 提交于 2019-12-02 21:47:59
Visual Studio complains: Warning 1 The designer must create an instance of type 'RentalEase.CustomBindingNavForm' but it cannot because the type is declared as abstract. Visual Studio won't let me access the Designer for the form. The class already implements all abstract methods from the CustomBindingNavForm. CustomBindingNavForm provides some functions concrete and abstract. Is there a way around this? Here is the class: public abstract class CustomBindingNavForm : SingleInstanceForm { //Flags for managing BindingSource protected bool isNew = false; protected bool isUpdating = false; ///

c# Abstract Class implementing an Interface

吃可爱长大的小学妹 提交于 2019-12-02 21:10:16
I've seen the following code layout reading forums and other blog posts and adapted in order to ask a few questions. public interface IService<T> { int Add(T entity); void Update(T entity); } public abstract class ServiceBase<T> : IService<T> { public int Add(T entity) { ... } public void Update(T entity) { ... } } public interface ICarService : IService<Car> { } public class SomeBaseClass : ServiceBase<Car>, ICarService { public int Add(Car entity); public void Update(Car entity); } What I don't understand is the benefit of having the abstract class implmenting the interface. To me it just

Should an abstract class have at least one abstract method?

ε祈祈猫儿з 提交于 2019-12-02 20:35:56
Is it necessary for an abstract class to have at least one abstract method? The subject of this post and the body ask two different questions: Should it have at least one abstract member? Is it necessary to have at least one abstract member? The answer to #2 is definitively no. The answer to #1 is subjective and a matter of style. Personally I would say yes. If your intent is to prevent a class (with no abstract methods) from being instantiated, the best way to handle this is with a private protected constructor, not by marking it abstract . No, it is not necessary. You see this often back in

Java: static abstract (again) - best practice how to work around

久未见 提交于 2019-12-02 20:25:37
I theoretically understand the point why there is no abstract static in Java, as explained for instance in Why can't static methods be abstract in Java . But how do I solve such a problem then? My application uses files of a few types, which I want to assign static properties like a description of that file type (like "data file", the other being "config file", etc.). Obviously, I would put that into a static String so that the description is accessible without instancing a file (useful for the GUI f.i.). On the other hand, obviously all file types should have some common methods like

Java final abstract class

情到浓时终转凉″ 提交于 2019-12-02 19:58:00
I have a quite simple question: I want to have a Java Class, which provides one public static method, which does something. This is just for encapsulating purposes (to have everything important within one separate class)... This class should neither be instantiated, nor being extended. That made me write: final abstract class MyClass { static void myMethod() { ... } ... // More private methods and fields... } (though I knew, it is forbidden). I also know, that I can make this class solely final and override the standard constructor while making it private. But this seems to me more like a

An Interface with Abstract Methods

十年热恋 提交于 2019-12-02 19:24:22
问题 I came across some PHP code that was written by a co-worker (it was not used for anything). Basically it was an interface containing abstract methods. I then said that this was stupid and showed another co-worker sitting next to me. We laughed but then started to ask each other if it was possible and if so if it was actually useful. Apparently it is not possible (see example below), but if it was possible would it be useful. Can you think of situations where this could be useful? <?php

Django: Best way to unit-test an abstract model

只谈情不闲聊 提交于 2019-12-02 19:04:54
I need to write some unit tests for an abstract base model, that provides some basic functionality that should be used by other apps. It it would be necessary to define a model that inherits from it just for testing purposes; are there any elegant/simple ways to define that model just for testing ? I have seen some "hacks" that make this possible, but never seen an "official" way in the django documentation or in other similar places. maikhoepfel Just stumbled across this feature myself: You can just inherit from your abstract model in tests.py and test that as usual. When you run 'manage.py

Can you re-make a method abstract in the inheritance tree?

醉酒当歌 提交于 2019-12-02 18:41:26
问题 EDIT: To be clear: The fact that the design is quite ugly is not the point. The point is, that the design is there and I am in the situation to have to add another sub-class of FlyingMotorizedVehicle which would not work as expected if I forgot to add the foo(...) . So I just was wondering if I could redefine it as abstract. I am right now facing a quite weird inheritance situation. Lets say, I have three classes, Vehicle , MotorizedVehicle and FlyingMotorizedVehicle as well as a bunch of