abstract

C++ multiple inheritance with base classes deriving from the same class

拟墨画扇 提交于 2019-12-19 08:58:57
问题 I have stumbled on a problem while trying to re-use code from different classes. I post it here in hope that some of you might be able to help me. I have a set of classes (B,C) deriving from the same class (A) which forces the implementation of some methods (foo, run). Class B implements these method, and both B and C provide other methods: #include<iostream> template<class I, class O> class A { public: A() {} virtual ~A() {} virtual void foo() const = 0; // force implementation of this

Java - Abstract class to contain variables?

微笑、不失礼 提交于 2019-12-19 05:03:19
问题 Is it good practice to let abstract classes define instance variables? public abstract class ExternalScript extends Script { String source; public abstract void setSource(String file); public abstract String getSource(); } The sub class, ExternalJavaScript.class, would then automatically get the source variable but I feel it's easier to read the code if all the sub classes themselves define the source, instead of from inheritance. What is your advice? /Adam 回答1: I would have thought that

opaque (abstract) data types in C

混江龙づ霸主 提交于 2019-12-19 04:55:30
问题 File api.h #include <stdio.h> #ifndef API #define API struct trytag; typedef struct trytag try; void trial (try *); #endif File core.h #ifndef CORE #define CORE struct trytag { int a; int b; }; #endif File func.c #include "api.h" #include "core.h" void trial (try *tryvar) { tryvar->a = 1; tryvar->b = 2; } File main.c #include "api.h" int main () { try s_tryvar; trial(&s_tryvar); printf("a = %d\nb = %d\n", s_tryvar.a, s_tryvar.b); } When I compile, I get: main.c:5: error: storage size of ‘s

Can I have an empty Java class?

走远了吗. 提交于 2019-12-19 04:17:26
问题 I'm creating a grid based game. I need to implement a set of obstacles that take random positions within the grid. I've created an abstract class ALifeForm , that holds the common methods for every item within the grid. Obviously, abstract classes can't be initialised, so I was going to create a new class AObstacle , which will extend ALifeForm . Only issue is, my AObstacle class isn't specialised. All the methods it needs are within ALifeForm . Can I have an empty class? Is it bad

What are the rules to handle homonym inherited methods?

纵饮孤独 提交于 2019-12-18 06:13:45
问题 I'm trying to understand how Java handles cases of ambiguity that come out when a concrete class inherits (abstract or concrete) methods having the same name from different classes/interfaces. I've not been able to find a general rule, this is why I decided, once for all, to spend some time on this by using a practical approach. I considered 8 different cases, combining abstract methods non-abstract methods abstract classes interfaces resulting in this scheme: +-------------------------+ |

static abstract methods in c++

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 03:51:15
问题 I have an abstract base class class IThingy { virtual void method1() = 0; virtual void method2() = 0; }; I want to say - "all classes providing a concrete instantiation must provide these static methods too" I am tempted to do class IThingy { virtual void method1() = 0; virtual void method2() = 0; static virtual IThingy Factory() = 0; }; I know that doesnt compile, and anyway its not clear how to use it even if it did compile. And anyway I can just do Concrete::Factory(); // concrete is

Abstract variables in Java?

一笑奈何 提交于 2019-12-17 22:38:34
问题 I am coming from c# where this was easy, and possible. I have this code: public abstract class clsAbstractTable { public abstract String TAG; public abstract void init(); } but Eclipse tells me I use illegal modifier. I have this class: public class clsContactGroups extends clsAbstractTable { } I want the variable and method defined in such way, that Eclipse to prompt me , I have unimplemented abstract variables and methods. How do I need to define my abstract class so I should be prompted to

c# Abstract Class implementing an Interface

大城市里の小女人 提交于 2019-12-17 22:22:21
问题 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

Best practices to test protected methods with PHPUnit (on abstract classes)

折月煮酒 提交于 2019-12-17 22:16:30
问题 With PHPUnit and PHP >= 5.3 it is possible to test protected methods. The following page at stackoverflow outlined the best practice on it: "Best practices to test protected methods with PHPUnit" protected static function callProtectedMethod($name, $classname, $params) { $class = new ReflectionClass($classname); $method = $class->getMethod($name); $method->setAccessible(true); $obj = new $classname($params); return $method->invokeArgs($obj, $params); } To test public methods on abstract

Why give an “abstract: true” state a url?

六月ゝ 毕业季﹏ 提交于 2019-12-17 10:18:32
问题 I've be fiddling around with ui-router today in trying to better understand the scaffolding in Ionic and one thing that I noticed was that they give the abstracted state of "tabs" a url. The only times I've ever used abstract states, I used an empty string as the url and I notice that if I've ever accidentally attempted to navigate to an abstracted state (as opposed to the child state) I get the error: Cannot transition to abstract state '[insertAbstractStateHere]' edit: "Moreover, in