subclass

Subclassing UIButton but can't access my properties

强颜欢笑 提交于 2019-11-27 22:52:33
问题 I've created a sub class of UIButton: // // DetailButton.h #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface MyDetailButton : UIButton { NSObject *annotation; } @property (nonatomic, retain) NSObject *annotation; @end // // DetailButton.m // #import "MyDetailButton.h" @implementation MyDetailButton @synthesize annotation; @end I figured that I can then create this object and set the annotation object by doing the following: MyDetailButton* rightButton = [MyDetailButton

Class extending more than one class Java?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 22:46:53
I know that a class can implement more than one interface, but is it possible to extend more than one class? For example I want my class to extend both TransformGroup and a class I created. Is this possible in Java? Both statements class X extends TransformGroup extends Y and class X extends TransformGroup, Y receive an error. And if it is not possible, why? TransformGroup extends Group but I guess it also extends Node since it inherits fields from Node and it can be passed where a Node object is required. Also, like all classes in Java, they extend Object class. So why wouldn't it be possible

C++ Disambiguation: subobject and subclass object

断了今生、忘了曾经 提交于 2019-11-27 22:41:56
问题 Basically what the title says. I have been referring to Base objects as subobjects. Is that correct and would it also be correct that subobject == superclass object ? Which one is preferred? The subclass means the derived class and the subclass object means the derived class' object, right? The confusion for me is that subclass object != subobject . If any of this is right, anyway.. Thanks 回答1: The C++ Standard has a clear definition of what a subobject is. That said, many people don't

ObservableCollection : calling OnCollectionChanged with multiple new items

风格不统一 提交于 2019-11-27 22:23:32
please note that I am trying to use NotifyCollectionChangedAction.Add action instead of .Reset. the latter does work, but it is not very efficient with large collections. so i subclassed ObservableCollection: public class SuspendableObservableCollection<T> : ObservableCollection<T> for some reason, this code: private List<T> _cachedItems; ... public void FlushCache() { if (_cachedItems.Count > 0) { foreach (var item in _cachedItems) Items.Add(item); OnCollectionChanged(new NotifyCollectionChangedEventArgs( NotifyCollectionChangedAction.Add, (IList<T>)_cachedItems)); } } is throwing A

Instance is an “object”, but class is not a subclass of “object”: how is this possible?

…衆ロ難τιáo~ 提交于 2019-11-27 22:08:21
How is it possible to have an instance of a class which is an object , without the class being a subclass of object ? here is an example: >>> class OldStyle(): pass >>> issubclass(OldStyle, object) False >>> old_style = OldStyle() >>> isinstance(old_style, object) True hamstergene In Python 2, type and class are not the same thing, specifically, for old-style classes, type(obj) is not the same object as obj.__class__ . So it is possible because instances of old-style classes are actually of a different type ( instance ) than their class: >>> class A(): pass >>> class B(A): pass >>> b = B() >>>

Should I subclass the NSMutableArray class

陌路散爱 提交于 2019-11-27 22:00:32
I have an NSMutableArray object that I want to add custom methods to. I tried subclassing NSMutableArray but then I get an error saying "method only defined for abstract class" when trying to get the number of objects with the count method. Why is the count method not inherited? I read somewhere else that I will have to import some NSMutableArray methods into my custom class if I want to use them. I just want to add a custom method to the NSMutableArray class. So should I subclass NSMutableArray, or should I do something else? PeyloW NSMutableArray is not a concrete class, it is just the

Protected fields not visible to subclasses

南楼画角 提交于 2019-11-27 21:21:24
I'm writing a custom view that directly extends android.view.View . If I try to access fields mScrollX or mScrollY , I see an error that the field "cannot be resolved or is not a field." The source code for android.view.View has mScrollX, mScrollY, and similar variables declared protected . How is it that my direct subclass cannot access protected fields of its parent class? (Classes like ScrollView apparently can.) P.S. I realize that I can call getScrollX() , but I want to update these fields; calling setScroll() has side effects that I don't want. It's because they are not part of the

Private members in Java inheritance

旧街凉风 提交于 2019-11-27 20:52:51
I was told that for a Java subclass it can inherit all members of its superclass. So does this mean even private members? I know it can inherit protected members. Can someone explain this to me. I am now totally confused. sgokhales No, the private member are not inherited because the scope of a private member is only limited to the class in which it is defined. Only the public and protected member are inherited. From the Java Documentation , Private Members in a Superclass A subclass does not inherit the private members of its parent class. However, if the superclass has public or protected

Getting the name of a sub-class from within a super-class

僤鯓⒐⒋嵵緔 提交于 2019-11-27 20:49:56
问题 Let's say I have a base class named Entity . In that class, I have a static method to retrieve the class name: class Entity { public static String getClass() { return Entity.class.getClass(); } } Now I have another class extend that. class User extends Entity { } I want to get the class name of User: System.out.println(User.getClass()); My goal is to see "com.packagename.User" output to the console, but instead I'm going to end up with "com.packagename.Entity" since the Entity class is being

Expose a private Objective-C method or property to subclasses

橙三吉。 提交于 2019-11-27 20:03:23
According to some official talk, a class in Objective-C should only expose public methods and properties in its header: @interface MyClass : NSObject @property (nonatomic, strong) MyPublicObject *publicObject; - (void)publicMethod; @end and private methods/properties should be kept in class extension in .m file: @interface MyClass() @property (nonatomic, strong) MyPrivateObject *privateObject; - (void) privateMethod; @end and I don't think there is a protected type for things that are private but accessible from subclasses. I wonder, is there anyway to achieve this, apart from declaring