subclass

iOS Parse PFObject Subclassing with Swift Behaviour

时光怂恿深爱的人放手 提交于 2019-12-04 06:30:13
问题 I have a strange issue, my subclassing works in all my view controllers except one. I have imported everything that is required, but this one class is giving me the "Missing argument for parameter 'className' in call" My subclass import Foundation import Parse class Session : PFObject, PFSubclassing { class func parseClassName() -> String { return "Session" } } // i have removed the non important info I perform the Session.registerSubclass() In the app delegate In EVERY class I have i can

python: dynamically adding attributes to a built-in class

烈酒焚心 提交于 2019-12-04 06:25:21
问题 Why doesn't it work for the built-in classes? Is using a subclass the best approach to fix it, or will I run into some hidden problems? a = {} a.p = 1 # raises AttributeError class B(dict): pass b = B() b.p = 1 # works EDIT: my original comment that it doesn't work for b was incorrect (I made a mistake). 回答1: The builtin classes do not have the ability to have arbitrary attributes. This is done for reasons of performance, especially memory usage, you want the built-in classes like list and

Subclass with additional method in Java

冷暖自知 提交于 2019-12-04 06:24:16
问题 I have a problem with a subclass in Java. I have the following class: MainIterator implements Iterator{ //... Methods from the interface Iterator public void foo(){ //Do something... } } and in my main class I call: Iterator i = new MainIterator(); i.foo(); which does not work, because Iterator does not implement the function foo() . How is it possible to get this working without a typecast of i ? i has to be from type Iterator. 回答1: MainIterator i = new MainIterator(); The Java compiler only

Why can't I subclass tuple in python3?

此生再无相见时 提交于 2019-12-04 05:51:00
Let's preface this question by saying that you should use __new__ instead of __init__ for subclassing immutable objects . With that being said, let's see the following code: class MyTuple(tuple): def __init__(self, *args): super(MyTuple, self).__init__(*args) mytuple = MyTuple([1,2,3]) This works in python2, but in python3 I get: Traceback (most recent call last): File "tmp.py", line 5, in <module> mytuple = MyTuple([1,2,3]) File "tmp.py", line 3, in __init__ super(MyTuple, self).__init__(*args) TypeError: object.__init__() takes no parameters Why does this happen? What changed in python3?

Delphi TListBox OnClick / OnChange?

試著忘記壹切 提交于 2019-12-04 05:04:15
Is there a trick to getting "OnChange" type of functionality with a TListBox? I can subclass the component and add a property, etc then only carry out OnClick code if the Index changes... I can also hack it with a form level variable to store the current index but just wondering if I'm overlooking the obvious before I go one way or the other. There seems to be no way other than implementing this by yourself. What you need is to remember the currently selected item and whenever the ItemIndex property is changed from code or whenever the control receives the LBN_SELCHANGE notification (which

Changing the value of superclass instance variables from a subclass

▼魔方 西西 提交于 2019-12-04 04:03:27
I've found that I can do it this way in the child class: ParentClass.variable = value; But I've been told that it's better practice to use get/set methods and not give direct access to variables outside a class. Though this was for when I had an instance of the class in another class, not for subclasses and superclasses. So is there a better way of doing this, and which way is generally considered best practice? You have a lot of options. super.field = x You have to have access to the field to do this field = x You have to have access to the field to do this. You also can't have another field

Can you subclass a generics class with a specific typed class?

梦想的初衷 提交于 2019-12-04 02:54:37
I have a generics class with a subclass that provides specific types. public abstract class GenericBase<T> where T:Interface1 { } I subclass the generics with specific implementations: public class Customer: GenericBase<Type1> ( Type1 implements Interface1 ). I have another abstract base class that has a reference to this: protected GenericBase<Interface1> genericInstance; Finally, when I attempt to assign the genericInstance to an instance of the base class, it gives me a compiler error, saying that it "cannot implicitly convert Customer to GenericBase<Interface1>". base.genericInstance = new

Why do Python immutable types (like int, str, or tuple) need to use `__new__()` instead of just `__init__()`?

眉间皱痕 提交于 2019-12-04 01:50:50
问题 This question is related to, but not a duplicate of, this, this, this, and this. Those links don't answer my question here. This though, almost answers my questions but doesn't, because the code in the answer doesn't run in Python 3.6 and in any case the question there isn't specifically about what I'm asking here. (See my own answer below. From the Python documentation page, I find the following text. __new__() is intended mainly to allow subclasses of immutable types (like int, str, or

list vs UserList and dict vs UserDict

旧巷老猫 提交于 2019-12-04 01:46:17
Coding this day, which of the above is preferred and recommended (both in Python 2 and 3) for subclassing? I read that UserList and UserDict have been introduced because in the past list and dict couldn't be subclassed, but since this isn't an issue anymore, is it encouraged to use them? Depending on your usecase, these days you'd either subclass list and dict directly, or you can subclass collections.MutableSequence and collections. MutableMapping ; these options are there in addition to using the User* objects. The User* objects have been moved to the collections module in Python 3; but any

Can I return a collection of multiple Derived Types from Dapper query

僤鯓⒐⒋嵵緔 提交于 2019-12-04 00:23:47
I have a class structure similar to this: public abstract class Device { public int DeviceId { get; set; } //Additional Properties } public class DeviceA : Device { //Specific Behaviour } public class DeviceB : Device { //Specific Behaviour } I need to retrieve a list of Devices, or a single Device which is instantiated as the appropriate derived type (based upon a Type value in the Device Record in the DB). That is, the collection of Device objects should contain a number of objects with different Types, all of which are derived from Device . I have implemented this the following way, but