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
12
votes
3 answers

Subclassing NSMutableDictionary

I am trying to implement a subclass of NSMutableDictionary that returns nil instead of throwing a NSUndefinedKeyException when the key is not present in the Dictionary. However when I try to add objects to my dictionary I get [NSMutableDictionary…
Ben
  • 532
  • 2
  • 4
  • 12
12
votes
6 answers

Why doesn't Apple allow subclassing of UINavigationController? And what are my alternatives to subclassing?

I'm currently building a tabbed iPhone application where each tab's view controller is an instance of UINavigationController, and where every subcontroller of every one of the UINavigationController instances is an instance of UITableViewController.…
11
votes
6 answers

Objective-C sub-classing basics, how to add custom property;

I am having a issue subclassing MKPolygon. I want to add a simple int tag property but I keep getting an instance of MKPolygon instead of my custom class, so calling setTag: causes an exception. The problem is that MKPolygons are created using a…
Zebs
  • 5,378
  • 2
  • 35
  • 49
11
votes
3 answers

Class cannot subclass 'QObject' (has type 'Any') using mypy

I have a class that subclasses QObject. Everyting works fine but when I run mypy on it I get the error: "error: Class cannot subclass 'QObject' (has type 'Any')" At the moment I am totally stuck. I Have been reading the mypy docs but couldn't find…
Notbad
  • 5,936
  • 12
  • 54
  • 100
11
votes
1 answer

Why can't I use a subclass of a generic type in Swift?

Why doesn't Swift allow me to assign value Foo to a variable of type Foo, where U is a subclass of T? For example: class Cheese { let smell: Int let hardness: Int let name: String init(smell: Int, hardness: Int, name: String)…
ConfusedByCode
  • 1,137
  • 8
  • 27
11
votes
2 answers

Overriding a variadic method in objective-c

When subclassing in objective-c, how can I forward a call to the superclass in the case of a variadic method. By what should I replace the ??? below to send all the objects I got? - (void) appendObjects:(id) firstObject, ... { [super…
Thomas
  • 10,358
  • 4
  • 27
  • 35
11
votes
2 answers

Subclassing file by subclassing `io.TextIOWrapper` — but what signature does its constructor have?

I'm trying to subclass io.TextIOWrapper following this post, although my aims are different. Starting off with this (NB: motivation): class MyTextIOFile(io.TextIOWrapper): def read(self, *args): cont = super().read(*args) return…
gerrit
  • 24,025
  • 17
  • 97
  • 170
11
votes
4 answers

Overriding default value of instance var

Given class Obj, class Obj: NSObject { var x = "x" } and its subclass, Obj1, how do you change the default value of var x? Simply setting a new value would make the most sense, but it seems to error out... class Obj1: Obj { var x =…
Patrick Perini
  • 22,555
  • 12
  • 59
  • 88
11
votes
1 answer

Proper way to replace NSTextStorage in NSTextView?

I am making some text viewer app. Currently I need very frequent and precise line handling ability, so I want to subclass NSTextStorage class. But I couldn't find any method to set a new text storage to NSTextView. The only method I could find was…
eonil
  • 83,476
  • 81
  • 317
  • 516
10
votes
1 answer

How to override internal framework method in application (outside framework)

Is there anyway to override internal framework method when subclassing in Swift? Ex. Superclass public class BarChartRenderer: ChartDataRendererBase { internal func drawDataSet(context context: CGContext, dataSet: BarChartDataSet, index: Int)…
Mateusz Tylman
  • 271
  • 1
  • 2
  • 17
10
votes
1 answer

Required initializers for a subclass of UIViewController

I've been attempting to follow a tutorial about creating a container view controller. It's in Objective-C. I want to convert it to Swift. I've found some of the same questions here, but I didn't get too much out of them. Here's the code. import…
Jeffrey
  • 1,271
  • 2
  • 15
  • 31
9
votes
3 answers

Why do cell renderers often extend JLabel?

I noticed this is common. For example DefaultListCellRenderer, DefaultTableCellRenderer, and DefaultTreeCellRenderer all use it. Also a lot of the custom cell renderers I see online use this as well. I want to use a custom TableCellRenderer in my…
Eva
  • 4,397
  • 5
  • 43
  • 65
9
votes
3 answers

Is subclassing a User model really bad to do in Rails?

I am getting lots of push back from Rails because I have subclassed User into many different subclasses. In my application, not all users are equal. There's actually a lot of model objects and not every User type has access to them. I also need a…
Fire Emblem
  • 5,961
  • 3
  • 24
  • 37
9
votes
1 answer

Dart / Flutter subclassing to use optional parameters

I am trying to figure out how to create a subclass of a class without specifying all the optional parameters of the parent but still have access to them from the Constructor of the child subclass. This is especially important when subclassing…
user603749
  • 1,638
  • 2
  • 24
  • 36
9
votes
1 answer

How to subclass custom Cell class with xib in swift

I got stuck with simple issue and can't find any solution. MyCell.xib has fileowner MyCell : UITableViewCell class. I use it like that: viewDidLoad method: let nib = UINib(nibName: "MyCell", bundle: nil) self.tableView.register(nib,…
John Kakon
  • 2,531
  • 4
  • 24
  • 28
1 2
3
55 56