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

UIView subclass with its own XIB

I created a custom UIView subclass, and would prefer to not layout the UI in code in the UIView subclass. I'd like to use a xib for that. So what I did is the following. I created a class "ShareView" which subclasses UIView. I created a XIB file…
ThomasM
  • 2,647
  • 3
  • 25
  • 30
21
votes
4 answers

C++ subclassing access modifier?

I'm C++ newbie, and I have many years of experience about OO languages such as C/C#/Objective-C. Now, I'm learning C++. I saw this C++ code: class World : public State { }; It seems class World inherits the class State publicly. Public…
eonil
  • 83,476
  • 81
  • 317
  • 516
19
votes
6 answers

wtforms Form class subclassing and field ordering

I have a UserForm class: class UserForm(Form): first_name = TextField(u'First name', [validators.Required()]) last_name = TextField(u'Last name', [validators.Required()]) middle_name = TextField(u'Middle name', [validators.Required()]) …
sector119
  • 888
  • 8
  • 12
19
votes
4 answers

What to consider before subclassing list?

I was recently going over a coding problem I was having and someone looking at the code said that subclassing list was bad (my problem was unrelated to that class). He said that you shouldn't do it and that it came with a bunch of bad side effects.…
Edward Williams
  • 596
  • 7
  • 25
19
votes
3 answers

How to change parent attribute in subclass python

I have the following class class Foo(): data = "abc" And i subclass it class Bar(Foo): data +="def" I am trying to edit a parent class attribute in subclass. I want my parent class to have some string, and my subclass should add some extra…
George
  • 988
  • 2
  • 10
  • 25
19
votes
5 answers

Is there a way to forbid subclassing of my class?

Say I've got a class called "Base", and a class called "Derived" which is a subclass of Base and accesses protected methods and members of Base. What I want to do now is make it so that no other classes can subclass Derived. In Java I can…
Jeremy Friesner
  • 70,199
  • 15
  • 131
  • 234
18
votes
4 answers

creating a defaultlist in python

I'm trying to create a list equivalent for the very useful collections.defaultdict. The following design works nicely: class defaultlist(list): def __init__(self, fx): self._fx = fx def __setitem__(self, index, value): while…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
17
votes
4 answers

What is subclassing?

I am new to java and I am trying to create an XML document and clone a specific node (minus the textnode) of this document over and over again. Someone answered me and said that I should subclass the node and override the cloning. So my question is…
codenamejupiterx
  • 1,589
  • 9
  • 23
  • 34
16
votes
5 answers

Subclassing PFObject in Swift

The Parse documentation for adding properties and methods on PFObject subclasses conveniently skips the Swift syntax in their sample code listing just the Objective-C syntax: https://parse.com/docs/ios_guide#subclasses-properties/iOS //…
user3806775
  • 169
  • 1
  • 3
16
votes
10 answers

OOP. Choosing objects

I'm a relative newbie to thinking in OOP terms, and haven't yet found my ‘gut instinct’ as to the right way to do it. As an exercise I'm trying to figure out where you'd create the line between different types of objects, using the drinks on my desk…
creednmd
  • 2,001
  • 2
  • 18
  • 25
15
votes
1 answer

Calling super.init() in initializer of NSObject subclass in Swift

I'm building an iOS app in Swift and drawing on the Lister sample project Apple provides. Lister uses two model objects: List and ListItem. I found that both of them do not call super.init() in their initializers even though they subclass…
sdduursma
  • 2,651
  • 3
  • 16
  • 16
14
votes
2 answers

How can I add a test method to a group of Django TestCase-derived classes?

I have a group of test cases that all should have exactly the same test done, along the lines of "Does method x return the name of an existing file?" I thought that the best way to do it would be a base class deriving from TestCase that they all…
JivanAmara
  • 1,065
  • 2
  • 10
  • 20
14
votes
3 answers

How to subclass custom UIViewController in Swift?

I'd like to create a reusable view controller UsersViewControllerBase. UsersViewControllerBase extends UIViewController, and implements two delegates (UITableViewDelegate, UITableViewDataSource), and has two views (UITableView,…
Alexey
  • 7,127
  • 9
  • 57
  • 94
13
votes
5 answers

In C++, does overriding an existing virtual function break ABI?

My library has two classes, a base class and a derived class. In the current version of the library the base class has a virtual function foo(), and the derived class does not override it. In the next version I'd like the derived class to override…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
12
votes
3 answers

Is there a way to create subclasses on-the-fly?

I'm creating a game in which I have a somewhat complex method for creating entities. When a level is loaded, the loading code reads a bunch of YAML files that contain attributes of all the different possible units. Using the YAML file, it creates a…
Louis Thibault
  • 20,240
  • 25
  • 83
  • 152
1
2
3
55 56