abstract-class

Why can abstract methods only be declared in abstract classes?

ぃ、小莉子 提交于 2020-01-22 06:54:27
问题 I understand that in abstract classes methods be both abstract, or not. But why can I not create an abstract method in a "normal", non-abstract class? Thanks in advance for any explanation! 回答1: Abstract method basically says, that there is no implementation of the method and it needs to be implemented in a subclass . However if you had an abstract method in a non-abstract class, you could instantiate the class and get an object, that would have an unimplemented method, which you would be

Difference between Trait and an Abstract Class in PHP

假如想象 提交于 2020-01-22 04:58:05
问题 I recently came across Traits in PHP and I'm trying to understand them. During my research I stumbled upon this Stack Overflow question: Traits vs. Interfaces. The accepted answer mentions the following: An interface defines a set of methods that the implementing class must implement. When a trait is use'd the implementations of the methods come along too--which doesn't happen in an Interface. So far so good but this sounds exactly like the difference between an interface and an abstract

@ModelAttribute and abstract class

☆樱花仙子☆ 提交于 2020-01-21 10:13:53
问题 I know that there have been similar questions. The examples given in them are too fragmentary and unclear. I need to edit the entities through a form on the page that sends the POST. The standard method is a method in the controller uses the parameter with @ModelAttribute and validator. If one form serves some subclass of an abstract class, there are no problems with the generation of the necessary fields, but there is a problem in the controller. As I understand it, @ModelAttribute works

@ModelAttribute and abstract class

送分小仙女□ 提交于 2020-01-21 10:09:35
问题 I know that there have been similar questions. The examples given in them are too fragmentary and unclear. I need to edit the entities through a form on the page that sends the POST. The standard method is a method in the controller uses the parameter with @ModelAttribute and validator. If one form serves some subclass of an abstract class, there are no problems with the generation of the necessary fields, but there is a problem in the controller. As I understand it, @ModelAttribute works

What's the point in having an abstract class with no abstract methods?

谁说我不能喝 提交于 2020-01-21 03:28:26
问题 Can have an abstract class implementing all of its methods -- with no abstract methods in it. Eg.: public abstract class someClass { int a; public someClass (int a) { this.a = a; } public void m1 () { /* do something */ } private void m2 () { /* do something else */ } } What's the advantage, if any, of having such an abstract class compared to having the same class as a concrete one instead? One i can think of is that, when i declare it as abstract, it won't be instantiated. however, i can

How do I make an abstract class properly return a concrete instance of another abstract class?

社会主义新天地 提交于 2020-01-17 12:52:45
问题 I recently reworked one of my own libraries to try out separating interface from implementation. I am having on final issue with a class that is meant to return an instance of another class. In the interface definition, I do something like struct IFoo { virtual const IBar& getBar() = 0; } and then in the concrete Foo getBar looks like const IBar& Foo::getBar() { Bar ret = Bar(); return ret; } The problem is ret gets deleted as soon as getBar is done, causing a big crash when the copy

How do I make an abstract class properly return a concrete instance of another abstract class?

时间秒杀一切 提交于 2020-01-17 12:52:11
问题 I recently reworked one of my own libraries to try out separating interface from implementation. I am having on final issue with a class that is meant to return an instance of another class. In the interface definition, I do something like struct IFoo { virtual const IBar& getBar() = 0; } and then in the concrete Foo getBar looks like const IBar& Foo::getBar() { Bar ret = Bar(); return ret; } The problem is ret gets deleted as soon as getBar is done, causing a big crash when the copy

Create generic abstract class using EF database first approach

会有一股神秘感。 提交于 2020-01-17 07:15:10
问题 I have some similar entities and I want to create a generic abstract class for CRUD operations for them, but I don't know how can access to entities in generic class. For example: public abstract class HeaderRepository<T> { public HeaderRepository() { } public virtual byte[] Insert(T item) { using (MyEntities context = new MyEntities()) { context.***** <-- What I should write to add an object to entity T } } } I hope I've got it. 回答1: You need to set your DB set. It would be better to have a

Abstract Constructor on Abstract Class in TypeScript

泪湿孤枕 提交于 2020-01-15 09:42:27
问题 How can I create an abstract constructor for an abstract class? For example, if I have this abstract class: export abstract class Foo<T> extends Bar<T> { constructor(someParam: any) { super(); this.someObj = someParam; } } Then it is consumed by this class: export class FooImpl extends Foo<SomeType> { } If I don't override the constructor then the default parameterless constructor will be used on the FooImpl class which will lead to an improper state within the class. How can I define an

C++11 alternative to the Java anonymous callback class

痞子三分冷 提交于 2020-01-15 06:20:10
问题 I realise that the solution I have here is far from ideal with C++, so I'm asking what a proper C++ programmer would do in this situation. (C++11) I have a DialogBox class, which stores a collection of buttons. At the moment I have a pure abstract inner class DialogBox::Button with the pure virtual function virtual void callback() const . From Java I'm used to using this strategy to create and instantiate an anonymous class deriving from Button in-place which implements the callback function.