subclass

Should a plugin adding new instance-methods monkey-patch or subclass/mixin and replace the parent?

元气小坏坏 提交于 2019-12-12 14:21:15
问题 As a simple example take a class Polynomial class Polynomial(object): def __init__(self, coefficients): self.coefficients = coefficients for polynomials of the form p(x) = a_0 + a_1*x + a_2*x^2 + ... + a_n*x^n where the list coefficients = (a_0, a_1, ..., a_n) stores those coefficients. One plugin-module horner could then provide a function horner.evaluate_polynomial(p, x) to evaluate a Polynomial instance p at value x , i.e. return the value of p(x) . But instead of calling the function that

Does a subclass NEED to have a constructor?

对着背影说爱祢 提交于 2019-12-12 10:55:24
问题 I've been learning about inheritance and I was just curious. I know that the subclass will automatically call the superclass's constructor even if you don't use the super() operator, so I wanted to know if it is even necessary for a subclass to have a constructor in it. 回答1: A subclass needs a constructor if the superclass does not have a default constructor (or has one that is not accessible to the subclass). If the subclass has no constructor at all, the compiler will automatically create a

How can subclasses share behavior when one already derives from a different base class?

扶醉桌前 提交于 2019-12-12 10:40:03
问题 I have two classes that implement ISomeBehavior. Now I want them to share functionality. Normally I would replace ISomeBehavior with an abstract class, like SomeBehaviorBase. The problem is that one of the subclasses already derives from another class, and that other class isn’t software we own. (This is C#, so multiple inheritance isn't an option.) The subclass, that derives from the 3rd party class, has no implementation. It simply derives from the 3rd party class, and implements

iOS: Changing subclass from UIView to UIScrollView in a storyboard

≯℡__Kan透↙ 提交于 2019-12-12 07:45:21
问题 I have created a storyboard based project. In one of the view controller's view requires some extra elements to be placed which results in increasing the view height such that the view must now be scrollable. Is it possible to simply change the class type of UIView to UIScrollView in storyboard? Will it really convert the top level UIView to UIScrollView ? Just looking for a quick and easy way of doing this without much changes. Thanks 回答1: You can open storyboard as an xml source code file,

Inherit from two classes

旧巷老猫 提交于 2019-12-12 05:48:47
问题 I am creating an universal iOS app, i.e. it will run on the iPhone and iPad. I now have a UIViewController that will be displayed on both, but differently. On the iPhone, it will contain a UITableView , on the iPad an AQGridView . The data will be the same. Both controllers will therefore share a lot of methods and instance variables. Usually, I would create a UIViewController subclass with my methods and instance variables and then create two subclasses of this class where I put the stuff

How to remove gray border from NSButton?

十年热恋 提交于 2019-12-12 05:28:54
问题 I´m trying to make a simple colored NSButton. It seems there are two problems i don´t get solved: 1. How can I stop the button from being highlighted when clicked? I set a red background to my button: . When clicked, the color disappears: How could I keep the backgroundcolor, even when the button is clicked?. How could I remove the gray border? I tried different things: class myButton: NSButton { override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) self.wantsLayer = true self

Declaring a class and subclass in two different files in python

旧时模样 提交于 2019-12-12 05:16:40
问题 I have two files, one declaring a superclass which involves a method involving a subclass, and the other defining the subclass. File1: from file2 import subclass class superclass: def __init__(self): "Stuff" def method(self): temp = subclass() "Stuff" File2: from file1 import superclass class subclass(superclass): def __init__(self): "Stuff" When I run file1's code I get an error inside file2 that superclass is not defined. This is because I import file2 before defining the superclass.

Java: reading from an input file, then moving data into subclasses

吃可爱长大的小学妹 提交于 2019-12-12 05:15:59
问题 Early stages of a simulation project, when this program runs, its supposed to read in a file such as the one below, then it should process each neuron and synapse through the program. There are two types of synapse, unnamed synapses and named ones. Synapse X above is a named synapse connecting neurons A and B. Unnamed synapses have a single dash in the name field. Neuron and synapse names be non-numeric. Any synapse that is named may be the target of a secondary synapse. The synapse B X above

Getting gestures to work with Subclassed UIButton

佐手、 提交于 2019-12-12 03:04:30
问题 I have a subclassed UIButton (DragButton) that I would like to be able to perform pan / pinch / rotate on. Instances of DragButton are created programmatically. There may be 1, there may be 20. All depends on the user. I am experiencing issues in getting these subclassed buttons to properly work with gestures. The main issue is none of the gestures trigger! Within DragButton class, inside the awakeFromNib instance method, the gestures don't work at all. Inside layoutSubviews, the panning

subclass override method not being called

懵懂的女人 提交于 2019-12-12 02:25:41
问题 I created a subclass of UITextField to override the method rightViewRectForBounds. Here is my custom class CustomTextField @interface CustomTextField : UITextField @end @implementation CustomTextField // override rightViewRectForBounds method: - (CGRect)rightViewRectForBounds:(CGRect)bounds{ NSLog(@"rightViewRectForBounds"); CGRect rightBounds = CGRectMake(bounds.origin.x + 10, 0, 30, 44); return rightBounds ; } @end Now I set up my ViewController to call the custom class instead of