abstract

An Interface with Abstract Methods

╄→гoц情女王★ 提交于 2019-12-02 12:27:45
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 interface Itest { abstract public function add(int $x, int $y); } abstract class ParentTest implements Itest

Typescript typings, generics and abstract classes

筅森魡賤 提交于 2019-12-02 11:27:21
问题 I experiment a behavior that seems strange to me. Let's consider the following sample (test it in Typescript playground): abstract class FooAbstract { abstract bar() {} } class Foo extends FooAbstract { bar() { return { bar: 'bar' }; } } class FooMaker<FOO extends FooAbstract> { constructor(public foo: FOO) {} bar() { return this.foo.bar(); } baz = () => { return this.foo.bar(); } } let foo = new Foo(); let result = foo.bar(); let foomaker = new FooMaker(new Foo); let foo2 = foomaker.foo; //

What's the difference between virtual function instantiations in C++?

北战南征 提交于 2019-12-02 11:01:11
问题 What's the difference between the following two declarations? virtual void calculateBase() = 0; virtual void calculateBase(); I read the first one (=0) is a "pure abstract function" but what does that make the second one? 回答1: First one is called a pure virtual function. Normally pure virtual functions will not have any implementation and you can not create a instance of a class containing a pure virtual function. Second one is a virtual function (i.e. a 'normal' virtual function). A class

How jvm handles abstract class in java

一曲冷凌霜 提交于 2019-12-02 09:53:48
I have a very basic question about abstract class in java. As we know that we can't create an instance of an abstract class, then how JVM handles the instantiation of abstract class in java . we can define a parameterized constrcutor in the abstract class and we can define another which extends the abstract class. In this situation who creates the instance of abstract class and invokes the constructor of the abstract class. I want to understand, How JVM manages the object creation of abstract classes. JVM cannot instantiate an abstract class it can instantiate only an instance of a non

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

浪尽此生 提交于 2019-12-02 09:23:50
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 classes Airplane , Helicopter , ...: public abstract class Vehicle { abstract Something doStuff(...);

Array of base abstract class containing children class in C++

拟墨画扇 提交于 2019-12-02 09:00:34
so I have a Top class, let say: //Top.h #pragma once #include <string> using std::string; class Top { protected: string name; public: virtual string GetName() = 0; } This class won't have any object Top instantiate, that's why it's an abstract class. I also have two Middle class, let say: //MiddleA.h #pragma once #include "Top.h" class MiddleA : public Top { protected: int value; public: MiddleA(string, int); string GetName(); int GetValue(); } //MiddleB.h class MiddleB : public Top { protected: double factorial; public: MiddleB(string, double); string GetName(); double GetFactorial(); double

Is it possible to override a superclass' method with a parameter extending the superclass' method parameter?

纵然是瞬间 提交于 2019-12-02 08:14:30
问题 Say I have a class like so: abstract class Something {} And it has a hierachy with classes extending it: class FirstSomething extends Something {} class SecondSomething extends Something {} Then elsewhere I have a class making use of these somethings: abstract class A { public void setSomething(Something something) { //Process the something } } Am I able to specify a subclass of A, so that it overrides the setSomething method, with the more specific "something" classes? This is what I want to

Typescript typings, generics and abstract classes

删除回忆录丶 提交于 2019-12-02 04:17:57
I experiment a behavior that seems strange to me. Let's consider the following sample ( test it in Typescript playground ): abstract class FooAbstract { abstract bar() {} } class Foo extends FooAbstract { bar() { return { bar: 'bar' }; } } class FooMaker<FOO extends FooAbstract> { constructor(public foo: FOO) {} bar() { return this.foo.bar(); } baz = () => { return this.foo.bar(); } } let foo = new Foo(); let result = foo.bar(); let foomaker = new FooMaker(new Foo); let foo2 = foomaker.foo; // Type "Foo", OK let result1 = foomaker.foo.bar(); // Type "{bar: string}", OK let result2 = foomaker

What's the difference between virtual function instantiations in C++?

别等时光非礼了梦想. 提交于 2019-12-02 03:14:08
What's the difference between the following two declarations? virtual void calculateBase() = 0; virtual void calculateBase(); I read the first one (=0) is a "pure abstract function" but what does that make the second one? First one is called a pure virtual function. Normally pure virtual functions will not have any implementation and you can not create a instance of a class containing a pure virtual function. Second one is a virtual function (i.e. a 'normal' virtual function). A class provides the implementation for this function, but its derived class can override this implementation by

Correct design for entity classes. Need recommendations

我的未来我决定 提交于 2019-12-02 00:07:55
For example, I have entity class User : public class User { private long id; private String name; // setters and getters } Next, I add new entity class: Comment public class Comment { private long id; private String comment; // setters and getters } Next, I can add more and more entity classes. And, at this moment I think: I can/must bind/connect in logical structure my entity classes or no? What I mean? I try explain: Point 1: All this classes: User , Comment and more other - POJO . Idea 1: Need logical binding for this classes via interface or abstract class. Point 2: I see, that All entity