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
1 answer

Python: How to subclass while calling parent class?

I have the following class which is being subclassed: class ConnectionManager(object): def __init__(self, type=None): self.type = None self.host = None self.username = None self.password = None …
user10503628
6
votes
1 answer

problem subclassing builtin type

# Python 3 class Point(tuple): def __init__(self, x, y): super().__init__((x, y)) Point(2, 3) would result in TypeError: tuple() takes at most 1 argument (2 given) Why? What should I do instead?
max
  • 49,282
  • 56
  • 208
  • 355
6
votes
1 answer

How do you properly write and use a View subclass in Android?

I am trying to implement one of the solutions found here. My problem is that I'm not sure if I am implementing and using my subclass correctly. I am subclassing a WebView here: public class myWebView extends WebView{ public myWebView(Context…
joepetrakovich
  • 1,344
  • 3
  • 24
  • 42
6
votes
5 answers

Modify subclassed string in place

I've got the following string subclass: class S(str): def conc(self, next_val, delimiter = ' '): """Concatenate values to an existing string""" if not next_val is None: self = self + delimiter + next_val …
mwolfe02
  • 23,787
  • 9
  • 91
  • 161
6
votes
2 answers

Is there a way to change the speed of scrollRectToVisible?

Is there a way to change how quickly scrollRectToVisible animates when scrolling a UIScrollView?
Moshe
  • 57,511
  • 78
  • 272
  • 425
6
votes
3 answers

Cannot create subclass of SKSpriteNode

Trying to subclass SKSpriteNode so make my game code cleaner, and I'm obviously not understanding something. Here's a very simple example: I create a new Swift file called Alien.swift with the following contents: import SpriteKit class Alien:…
Steve Ives
  • 7,894
  • 3
  • 24
  • 55
6
votes
1 answer

issubclass of abstract base class Sequence

This list shows what methods you need to implement for your class to be "regarded" as Sequence: __getitem__, __len__, __contains__, __iter__, __reversed__, index, and count. So why does this minimal implementation does not work, i.e. why…
Kijewski
  • 25,517
  • 12
  • 101
  • 143
6
votes
3 answers

overriding UIImage(named: )

I was on my way to override UIImage class method init(named:). My goal is to be able to retrieve the file name of an image. The code would look like this: class UIImageWithFileName: UIImage { let fileName: String override…
potato
  • 4,479
  • 7
  • 42
  • 99
6
votes
3 answers

Swift calling subclass's overridden method from superclass

I was having an issue with a subclass's method getting called that overrode a method, so I created a small app to test it. When the superclass calls a method that its subclass overrides, the superclass's version of the method still gets called…
Adam Evans
  • 2,072
  • 1
  • 20
  • 29
6
votes
0 answers

Fluent nHibernate - DiscriminateSubClassesOnColumn with multiple tables?

I've been trying to wrap my head around subclasses and joined subclasses in Fluent nHibernate for a few days now without making any sort of headway. I've looked at the wiki but it doesn't seem to give me enough information, and googling returns me…
6
votes
5 answers

How should I construct a subclass using an instance of the superclass?

Let's say I have the following code public class SuperClass { protected int super_class_value; public SuperClass (int value) { this.super_class_value = value; } } public class Subclass extends SuperClass { protected int…
Tester101
  • 8,042
  • 13
  • 55
  • 78
6
votes
2 answers

Is there a way to subclass a generator in Python 3?

Aside from the obvious, I thought I'd try this, just in case: def somegen(input=None): ... yield ... gentype = type(somegen()) class subgen(gentype): def best_function_ever(): ... Alas, Python's response was quite…
Inversus
  • 3,125
  • 4
  • 32
  • 37
6
votes
2 answers

Qt/C++ Override function without subclassing

I would like to override a virtual function of a QWidget without subclassing it. It is possible in java. I found this link: overriding methods without subclassing in Java Not sure if there is a way in c++ too. Any ideas?
Cocomico
  • 878
  • 7
  • 18
6
votes
3 answers

Objective-C Mutable subclass pattern?

Is there a standard pattern for implementing a mutable/immutable object class pair in Objective-C? I currently have something like the following, which I wrote based off this link Immutable Class: @interface MyObject : NSObject { …
wL_
  • 997
  • 8
  • 13
6
votes
1 answer

Calling a subclass's getter in Swift

So, while playing around with Swift, I ran into this issue and it's boggling my mind. I have a class Card: class Card { var contents = "" var chosen = false var matched = false var description: String { get { return…
Atharv Vaish
  • 155
  • 1
  • 6