Questions tagged [base-class]

In Object Oriented Programming, a base class is one from which other classes inherit. For example, a child-class `Male` and another child-class `Female` may both inherit from the base-class `Human`.

In Object Oriented Programming, a base class is one from which other classes inherit. For example, a child-class Male and another child-class Female may both inherit from the base-class Human. As a result of such an inheritance, each of them will have at least all the attributes and methods of the class Human and perhaps a few others.

678 questions
28
votes
3 answers

ExecuteCore() in base class not fired in MVC 4 beta

I have a base controller class: And all my other controller inherits this BaseClass like this All this works great in MVC3 (test again today, it really works) but it seems that the ExecuteCore in BaseController is not fired any more in MVC 4…
BladeLeaf
  • 458
  • 1
  • 4
  • 8
27
votes
4 answers

Why use base class pointers for derived classes

class base{ ..... virtual void function1(); virtual void function2(); }; class derived::public base{ int function1(); int function2(); }; int main() { derived d; base *b = &d; int k = b->function1() // Why use this…
Balaji Sridharan
  • 339
  • 1
  • 5
  • 7
27
votes
2 answers

Non-testable base class extending PHPUnit_Framework_TestCase

Summary How can I create a base class that extends PHPUnit_Framework_TestCase and use that for subclassing actual test cases, without having the base class itself tested by PHPUnit? Further explanation I have a series of related test cases for which…
jgivoni
  • 1,605
  • 1
  • 15
  • 24
27
votes
10 answers

What are good candidates for base controller class in ASP.NET MVC?

I've seen a lot of people talk about using base controllers in their ASP.NET MVC projects. The typical examples I've seen do this for logging or maybe CRUD scaffolding. What are some other good uses of a base controller class?
kenwarner
  • 28,650
  • 28
  • 130
  • 173
27
votes
3 answers

Can you extend the default JsonConverter used in JSON.NET for collections?

I'm trying to write a custom JsonConverter for cases where a person subclasses a list or collection, but then adds extra properties to the subclass (see here). The current implementation of JSON.NET just changes the list into an array of child…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
26
votes
2 answers

How can I polymorphic deserialization Json String using Java and Jackson Library?

I've some classes A, B, C they all inherit from class BaseClass. I've a String json that contains the json representation of the A, B, C or BaseClass. I want to have some way to deserialize this String to the BaseClass (polymorphic deserialization).…
mohamede1945
  • 7,092
  • 6
  • 47
  • 61
25
votes
5 answers

In .NET, can you use reflection to get all non-inherited methods of a class?

Because of this issue here, I'm trying to write a custom JsonConverter that handles cases where you subclass a list or a collection, then add extra properties to it. As such, one approach would be to ignore all base-class properties and only…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
24
votes
2 answers

How do derived class constructors work in python?

I have the following base class: class NeuralNetworkBase: def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs): self.inputLayer = numpy.zeros(shape = (numberOfInputs)) self.hiddenLayer = numpy.zeros(shape =…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
24
votes
2 answers

Android: Call super() at the beginning or end of onStart(), onStop(), onDestroy() in activity?

Where in onStart(), onStop(), onDestroy() of an activity do I call super.onStart(), super.onStop(), super.onDestroy() ?
mrd
  • 4,561
  • 10
  • 54
  • 92
22
votes
2 answers

Abstract base class in Dart

I have been programming in Java for nearly two years but I am now more shifting to web programming and thus to Javascript, or in my case to Dart. For a project I'm working on I would like to have abstract base classes, just I would have in Java. I…
Tomasito665
  • 1,188
  • 1
  • 12
  • 24
22
votes
2 answers

How do I call a derived class method from the base class?

I have read several similar questions about this but none seem to solve the problem I am facing. The typical answer is to cast as the derived class but I cannot since I do not know the derived class type. Here is my example: class WireLessDevice {…
CramerTV
  • 1,376
  • 1
  • 16
  • 29
21
votes
2 answers

Why is a base class in C# allowed to implement an interface contract without inheriting from it?

I've stumbled upon this "feature" of C# - the base class that implements interface methods does not have to derive from it. Example: public interface IContract { void Func(); } // Note that Base does **not** derive from IContract public…
etarassov
  • 329
  • 2
  • 5
20
votes
2 answers

Name lookup differences between g++ and MSVS

Consider this code: #include namespace N { class A {}; void f(A a) { std::cout << "N::f\n"; } } void f(int i) { std::cout << "::f\n"; } template class Base { public: void f(T x) { std::cout << "Base::f\n";…
oz1cz
  • 5,504
  • 6
  • 38
  • 58
20
votes
5 answers

Do you have a common base class for Hibernate entities?

Do you have a common base class for Hibernate entities, i.e. a MappedSuperclass with id, version and other common properties? Are there any drawbacks? Example: @MappedSuperclass() public class BaseEntity { private Long id; private Long…
cretzel
  • 19,864
  • 19
  • 58
  • 71
19
votes
5 answers

Calling a constructor of the base class from a subclass' constructor body

I was under impression that it's impossible, see for example: Calling the constructor of the base class after some other instructions in C++ But the following program runs and produces two lines of "Constructor Person": #include class…
TT_ stands with Russia
  • 1,785
  • 3
  • 21
  • 33
1
2
3
45 46