subclass

How can I change the default value of an inherited dependency property?

时光毁灭记忆、已成空白 提交于 2019-11-26 16:27:02
问题 How can I change the default value for an inherited dependency property? In our case, we've created a subclass of Control which by default has its Focusable set to 'true'. We want our subclass to have the default of 'false'. What we've been doing is simply setting it to 'false' in the constructor, but if someone uses ClearValue, it goes back to the default, not the value set in the constructor. Here's what I'm currently doing to achieve this (This is a test control with a DP of 'Foo' for an

Abstract classes in Swift Language

≡放荡痞女 提交于 2019-11-26 15:48:23
Is there a way to create an abstract class in the Swift Language, or is this a limitation just like Objective-C? I'd like to create a abstract class comparable to what Java defines as an abstract class. drewag There are no abstract classes in Swift (just like Objective-C). Your best bet is going to be to use a Protocol , which is like a Java Interface. With Swift 2.0, you can then add method implementations and calculated property implementations using protocol extensions. Your only restrictions are that you can't provide member variables or constants and there is no dynamic dispatch . An

Subclassing dict: should dict.__init__() be called?

懵懂的女人 提交于 2019-11-26 15:47:54
问题 Here is a twofold question, with a theoretical part, and a practical one: When subclassing dict: class ImageDB(dict): def __init__(self, directory): dict.__init__(self) # Necessary?? ... should dict.__init__(self) be called, just as a "safety" measure (e.g., in case there are some non-trivial implementation details that matter)? is there a risk that the code break with a future version of Python if dict.__init__() is not called? I'm looking for a fundamental reason of doing one thing or the

Java getMethod with subclass parameter

倖福魔咒の 提交于 2019-11-26 14:19:23
问题 I'm writing a library that uses reflection to find and call methods dynamically. Given just an object, a method name, and a parameter list, I need to call the given method as though the method call were explicitly written in the code. I've been using the following approach, which works in most cases: static void callMethod(Object receiver, String methodName, Object[] params) { Class<?>[] paramTypes = new Class<?>[params.length]; for (int i = 0; i < param.length; i++) { paramTypes[i] = params

Why aren&#39;t superclass __init__ methods automatically invoked?

断了今生、忘了曾经 提交于 2019-11-26 14:05:17
Why did the Python designers decide that subclasses' __init__() methods don't automatically call the __init__() methods of their superclasses, as in some other languages? Is the Pythonic and recommended idiom really like the following? class Superclass(object): def __init__(self): print 'Do something' class Subclass(Superclass): def __init__(self): super(Subclass, self).__init__() print 'Do something else' The crucial distinction between Python's __init__ and those other languages constructors is that __init__ is not a constructor: it's an initializer (the actual constructor (if any, but, see

python subclass access to class variable of parent

被刻印的时光 ゝ 提交于 2019-11-26 13:02:09
问题 I was surprised to to learn that a class variable of a subclass can\'t access a class variable of the parent without specifically indicating the class name of the parent: >>> class A(object): ... x = 0 ... >>> class B(A): ... y = x+1 ... Traceback (most recent call last): File \"<stdin>\", line 1, in <module> File \"<stdin>\", line 2, in B NameError: name \'x\' is not defined >>> class B(A): ... y = A.x + 1 ... >>> B.x 0 >>> B.y 1 Why is it that in defining B.y I have to refer to A.x and not

Rotating a view in layoutSubviews

故事扮演 提交于 2019-11-26 12:48:02
问题 Background and goal Goal: I want to rotate and flip a UITextView . ( Why: see my previous question) Problem: If I do the transform directly on the UITextView , the text layout gets messed up for some unknown reason. Solution: Put the UITextView in a UIView container, and then do the transform on the container. New problem: Auto Layout (or any sort of layout) on the rotated view becomes a major headache. Proposed solution: Make a subclass of UIView that acts as an additional container for the

How do I check (at runtime) if one class is a subclass of another?

岁酱吖の 提交于 2019-11-26 12:38:47
问题 Let\'s say that I have a class Suit and four subclasses of suit: Heart, Spade, Diamond, Club. class Suit: ... class Heart(Suit): ... class Spade(Suit): ... class Diamond(Suit): ... class Club(Suit): ... I have a method which receives a suit as a parameter, which is a class object, not an instance. More precisely, it may receive only one of the four values: Heart, Spade, Diamond, Club. How can I make an assertion which ensures such a thing? Something like: def my_method(suit): assert(suit

How can I implement single table inheritance using Laravel&#39;s Eloquent?

心不动则不痛 提交于 2019-11-26 12:09:17
问题 Currently I have a model class named Post . class Post extends Eloquent { protected $table = \'posts\'; protected $fillable = array(\'user_id\', \'title\', \'description\', \'views\'); /* * Relationships */ public function user() { return $this->belongsTo(\'User\'); } public function tags() { return $this->belongsToMany(\'Tag\', \'post_tags\'); } public function reactions() { return $this->hasMany(\'Reaction\'); } public function votes() { return $this->hasMany(\'PostVote\'); } //Scopes and

Make Background of UIView a Gradient Without Sub Classing

回眸只為那壹抹淺笑 提交于 2019-11-26 11:58:42
问题 Is there a way to make the background of a UIView a gradient without subclassing it? I\'d rather not use an image file to accomplish this either. It just seems obtuse to have to subclass UIView just to draw a gradient for the background. 回答1: You can use +[UIColor colorWithPatternImage:] to produce a patterned background. Example (bring your own CGGradient): // Allocate color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Allocate bitmap context CGContextRef