Questions tagged [subclassing]

A subclass, "derived class", heir class, or child class is a modular, derivative class that inherits one or more language entities from one or more other classes.

A subclass, "derived class", heir class, or child class is a modular, derivative class that inherits one or more language entities from one or more other classes (called superclasses, base classes, or parent classes). The semantics of class inheritance vary from language to language, but commonly the subclass automatically inherits the instance variables and member functions of its superclasses. Some languages support the inheritance of other construct as well. For example, in Eiffel, contracts which define the specification of a class are also inherited by heirs. The superclass establishes a common interface and foundational functionality, which specialized subclasses can inherit, modify, and supplement. The software inherited by a subclass is considered reused in the subclass. A reference to an instance of a class may actually be referring one of its subclasses. The actual class of the object being referenced is impossible to predict at compile-time. A uniform interface is used to invoke the member functions of objects of a number of different classes. Subclass may replace superclass functions with entirely new functions that must share the same method signature.

833 questions
7
votes
1 answer

Python/Keras - Creating a callback with one prediction for each epoch

I'm using Keras to predict a time series. As standard I'm using 20 epochs. I want to know what did my neural network predict for each one of the 20 epochs. By using model.predict I'm getting only one prediction among all epochs (not sure how Keras…
aabujamra
  • 4,494
  • 13
  • 51
  • 101
7
votes
1 answer

Subclassing WPF Window

I created a WPF Window than i modified its class definition to: public partial class myWindow : mySubclassedWindow compiler throws: "Partial declarations of 'myWindow' must not specify different base…
Sonic Soul
  • 23,855
  • 37
  • 130
  • 196
7
votes
3 answers

Which is better Java programming practice: stacking enums and enum constructors, or subclassing?

Given a finite number of items which differ in kind, is it better to represent them with stacked enums and enum constructors, or to subclass them? Or is there a better approach altogether? To give you some context, in my small RPG program (which…
Arvanem
  • 1,043
  • 12
  • 22
7
votes
2 answers

Define generic Type of parent class method depending on subclass Type in Java

Is it possible to dynamically identify T as a return type depending on subclass Type? I want something like the following: public class Parent { public T foo() { return (T)this; } } public class…
chaplean
  • 197
  • 1
  • 3
  • 10
7
votes
1 answer

Can't create a base model class in Play using Ebean

I am trying to create the following class in Play using Ebean: public class BaseModel extends Model { @Column(name = "created_at") public Date createdAt; @Column(name = "updated_at") public Date updatedAt; @PrePersist …
k9m
  • 295
  • 1
  • 3
  • 8
7
votes
1 answer

Derived class from numpy array does not play well with matrix and masked array

I am trying to subclass a numpy ndarray but I am not able to get right the operations with other numpy types such as masked array or matrix. It seems to me that the __array_priority__ is not being honored. As an example, I have created a dummy class…
Hernan
  • 5,811
  • 10
  • 51
  • 86
7
votes
2 answers

How to receive TAB key press in edit box?

i want to receive OnKeyPress events when the user presses the Tab key. procedure TForm1.Edit1(Sender: TObject; var Key: Char); begin case Key of #09: begin //Snip - Stuff i want to do end; end; end; i try subclassing…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
7
votes
2 answers

Python built-in types subclassing

What's wrong with this code? class MyList(list): def __init__(self, li): self = li When I create an instance of MyList with, for example, MyList([1, 2, 3]), and then I print this instance, all I get is an empty list []. If MyDict is subclassing…
whatyouhide
  • 15,897
  • 9
  • 57
  • 71
7
votes
2 answers

Mocking class properties while using 'autospec=True' in python

I wish to mock a class with the following requirements: The class has public read/write properties, defined in its __init__() method The class has public attribute which is auto-incremented on object creation I wish to use autospec=True, so the…
bavaza
  • 10,319
  • 10
  • 64
  • 103
6
votes
1 answer

How to subclass a subclass of numpy.ndarray

I'm struggling to subclass my own subclass of numpy.ndarray. I don't really understand what the problem is and would like someone to explain what goes wrong in the following cases and how to do what I'm trying to do. What I'm trying to achieve: I…
Ben Whale
  • 493
  • 2
  • 9
6
votes
2 answers

Subclassing and built-in methods in Python

For convenience, I wanted to subclass socket to create an ICMP socket: class ICMPSocket(socket.socket): def __init__(self): socket.socket.__init__( self, socket.AF_INET, socket.SOCK_RAW, …
grifaton
  • 3,986
  • 4
  • 30
  • 42
6
votes
3 answers

Singletons testing and subclassing

I saw this while using picocontainer. They say you have to avoid singletons. because the Singleton pattern makes it almost impossible for the class (and possibly all other classes which depend on it) to be testable. It's very hard to subclass, or to…
Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69
6
votes
6 answers

Why there are no OutOfMemoryError subclasses?

As we all know, there are multiple reasons of OutOfMEmoryError (see first answer). Why there is only one exception covering all these cases instead of multiple fine-grained ones inheriting from OutOfMEmoryError?
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
6
votes
1 answer

Pandas groupby, resample, etc for subclassed DataFrame

Note: The thread below prompted a pull request which was eventually merged into v1.10. This issue is now resolved. I'm using a subclassed DataFrame so that I can have more convenient access to some transformation methods and metadata particular to…
grge
  • 135
  • 10
6
votes
5 answers

Emulating the list.insert() method as a subclass of Python's list

I'm trying to build a class that inherits methods from Python's list, but also does some additional things on top... it's probably easier just to show code at this point... class Host(object): """Emulate a virtual host attached to a physical…
Mike Pennington
  • 41,899
  • 19
  • 136
  • 174