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
6
votes
2 answers

Choosing the right subclass to instantiate programmatically

Ok, the context is some serialization / deserialization code that will parse a byte stream into an 'object' representation that's easier to work with (and vice-versa). Here's a simplified example with a base message class and then depending on a…
246tNt
  • 2,122
  • 1
  • 16
  • 20
5
votes
4 answers

Am I subclassing my CSS correctly?

I am making a set of buttons for my site, and I am in need of some professional insight. In order to reduce CSS bloat, I want to subclass my buttons for different colors, ex .button.blue . Will the following incur issues in the future? (assuming I…
SkinnyG33k
  • 1,721
  • 4
  • 23
  • 30
5
votes
1 answer

Subclassing NSPredicate to add operator

Cocoa defines predicate classes (NSPredicate, NSExpression, etc.) which "provide a general means of specifying queries in Cocoa" Predicate Programming. This set of classes describes what I need but with one little short-coming : I'd like additional…
user1040049
5
votes
2 answers

Why does the protocol default value passed to the function not change, even though the function does when subclassing?

I have a protocol, to which I have assigned some default values: protocol HigherProtocol { var level: Int { get } func doSomething() } extension HigherProtocol { var level: Int { 10 } func doSomething() { …
Kramer
  • 338
  • 2
  • 15
5
votes
1 answer

When subclassing ndarray why does a transpose happen after __array_finalize__ and not before?

Let us for simplicity just copy the diagnostic ndarray subclass from the numpy docs: import numpy as np class MySubClass(np.ndarray): def __new__(cls, input_array, info=None): obj = np.asarray(input_array).view(cls) obj.info =…
Paul Panzer
  • 51,835
  • 3
  • 54
  • 99
5
votes
4 answers

Ruby - how to handle problem of subclass accidentally overriding superclass's private fields?

Suppose you write a class Sup and I decide to extend it to Sub < Sup. Not only do I need to understand your published interface, but I also need to understand your private fields. Witness this failure: class Sup def initialize @privateField =…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
5
votes
1 answer

How to select sub-classed Custom Elements with CSS

Consider the following: class MyElem extends HTMLElement {}; customElements.define('my-element', MyElem); class MyMoreSpecificElem extends MyElem {}; customElements.define('my-more-specific-element', MyMoreSpecificElem); In the parlance of object…
Jared Smith
  • 19,721
  • 5
  • 45
  • 83
5
votes
3 answers

changing curly brace as identifier in str.format()

format() method is awesome but I want to change identifier of my choice because I dont want to escape { and } in my string. e.g. 'Hi {name}'.format(**{'name': 'Alok'}) will print 'Hi Alok' 'Hi {{{name1}, {name2}}}'.format(**{'name1':'foo',…
Alok
  • 7,734
  • 8
  • 55
  • 100
5
votes
4 answers

Why can't I have an enum as the underlying type of another enum?

Why isn't this valid C++?: enum foo : unsigned { first_foo, second_foo }; enum bar : foo { best_foo = first_foo }; GCC 5.4.0 says: /tmp/a.cpp:3:16: error: underlying type ‘foo’ of ‘bar’ must be an integral type enum bar : foo { best_foo =…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
5
votes
2 answers

Method ignored when subclassing a type defined in a C module

I am subclassing a type defined in a C module to alias some attributes and methods so that my script works in different contexts. How is it that to get this to work, I have to tweak the dictionary of my class manually ? If I don't add a reference…
Jacques Gaudin
  • 15,779
  • 10
  • 54
  • 75
5
votes
6 answers

How to turn off beeping when pressing ENTER on a single-line EDIT control under Windows CE?

I'm developing an application targeted to a POCKET PC 2003 (Windows CE 4.2) device using C++ and native WINAPI (i.e. no MFC or the like). In it I have a single-line edit control which part of the main window (not a dialog); hence the normal…
gablin
  • 4,678
  • 6
  • 33
  • 47
5
votes
1 answer

new in Xcode 6.3/iOS 8.3: using self alloc for convenience constructor causes build error

This code did not change between Xcode 6.2 and 6.3, but the line containing [self alloc] now causes the error: Multiple methods named 'initWithType:' found with mismatched result, parameter type or attributes @implementation AGNetworkDataRequest +…
ray
  • 1,966
  • 4
  • 24
  • 39
5
votes
2 answers

Subclassing Parse's PFUser in Swift

First off, I know similar questions have been asked before and I've tried following the advice of this stackoverflow answer here to no avail. I also tried adding the basic gist of this as a comment, but I don't have enough rep yet :( Basically I am…
Derek Dowling
  • 479
  • 1
  • 4
  • 15
5
votes
0 answers

How do I ensure that my matplotlib axes are of a custom class?

I have a custom figure class and would like to ensure that all of the axes associated with it, whether created with subplots() or twinx(), etc. have custom behaviors. Right now I accomplish this by binding new methods to each axis after it has been…
orome
  • 45,163
  • 57
  • 202
  • 418
5
votes
2 answers

How do I remove an inherited object from a child without altering the parent

(note: names were changed to protect the guilty) So, let's say I am doing modifications in VisualCruft 8 (long since discontinued by the vendor), and applying those modifications to ERP software from "Company A" (long since bought out by "Company…
Avery Payne
  • 1,738
  • 2
  • 17
  • 31