subclass

Java: Can a class inherit from two super classes at the same time?

主宰稳场 提交于 2019-12-10 10:16:24
问题 I have a class Journey which I want to make a superclass and another class plannedjourney. The plannedjourney class extends JFrame since it contains forms..However I also want this class to extends Journey.. Is there a possible way to do this? 回答1: Don't mix models and views. If you keep both domains clearly separated, then you won't be in need of multiple inheritance (this time). You have one model class for journeys and a viewer for such journeys. The viewer should subclass Component and be

Subclassing NSLayoutConstraint constant based on screen height

僤鯓⒐⒋嵵緔 提交于 2019-12-10 10:14:29
问题 I have a project with a Tab Bar, and a custom Navigation bar for each of the tabs. Each of the Navigation bar UIViews have a height constraint constant set in the storyboard. I would like to subclass this NSLayoutConstraint (for the Nav height), so that it changes the height for iPhone X. The Navigation bar needs to be much taller on an iPhone X, and since I'm not using "out of the box" objects, my constraints need to be manually set. Essentially, I want to do something like the following in

Load a AQGridViewCell from XIB (not working)

徘徊边缘 提交于 2019-12-10 10:13:21
问题 I am using AQGridView class and I am trying to load a cell from an XIB . I have setup the XIB like a Custom Cell for a UITableView , but when I attempt to load the cell, it is simply blank. I was wondering if there was an easier way to get the XIB to load. AQGridViewCell need to load the cell from an xib - (AQGridViewCell *) gridView: (AQGridView *) gridView cellForItemAtIndex: (NSUInteger) index { static NSString * CellIdentifier = @"cellID"; gridCell * cell = (gridCell *)[gridView

Changing the value of superclass instance variables from a subclass

泪湿孤枕 提交于 2019-12-09 17:01:05
问题 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? 回答1: You have a lot of options. super.field = x You have to have access to the

list vs UserList and dict vs UserDict

↘锁芯ラ 提交于 2019-12-09 14:59:43
问题 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? 回答1: 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

How to “clone” an object into a subclass object?

早过忘川 提交于 2019-12-09 07:43:18
问题 I have a class A and a class B that inherits class A and extends it with some more fields. Having an object a of type A , how can I create an object b of type B that contains all data that object a contained? I have tried a.MemberwiseClone() but that only gives me another type A object. And I cannot cast A into B since the inheritance relationship only allows the opposite cast. What is the right way to do this? 回答1: There is no means of doing this automatically built into the language... One

Java: Getting the subclass from a superclass list

老子叫甜甜 提交于 2019-12-08 19:37:53
问题 i'm new with java and have 2 questions about the following code: class Animal { } class Dog extends Animal { } class Cat extends Animal { } class Rat extends Animal { } class Main { List<Animal> animals = new ArrayList<Animal>(); public void main(String[] args) { animals.add(new Dog()); animals.add(new Rat()); animals.add(new Dog()); animals.add(new Cat()); animals.add(new Rat()); animals.add(new Cat()); List<Animal> cats = getCertainAnimals( /*some parameter specifying that i want only the

When to call Python's super().__init__()?

半腔热情 提交于 2019-12-08 18:38:07
问题 (I am unable to find a reference anywhere on this matter after some Googling.) The scenario can be clearly demonstrated with this short code sample: class X: def __init__(self, stuff): self.__stuff = stuff class Y(X): def __init__(self, stuff): # Is it safe to execute statements before calling super.__init__()? new_stuff = self.call_another_method(stuff) super(Y, self).__init__(new_stuff) Using CPython 3.x, the above code sample works -- assuming call_another_method() exists. It this coding

Custom UIButton subclass not displaying title

淺唱寂寞╮ 提交于 2019-12-08 10:30:13
问题 Let me start off by saying I am aware that this is a frequently asked question, I just can't seem to find someone with the same scenario/problem as me. I am writing a music application, and I came up with a UI that I liked. It required a button with special functionality (past what can be achieved by the Custom Button type) so I decided to make a UIButton subclass. I used the following code in my subclass: required init(coder aDecoder: NSCoder) { self.activeState = false self.activeAccidental

VBA subclass reference

守給你的承諾、 提交于 2019-12-08 09:59:31
In this post there is the description of "subclass" usage in VBA. I'm looking for the next step of it: when I have first subitem added I want to use it and don't know how. When I write baseItem(1).itemName it doesn't work. I assume it's just because that baseItem is not a collection or an array, but I don't know any other way. I assume it's just because that baseItem is not a collection or an array... The baseItem itself is not a collection nor an array. It is just an object of type BaseClass . But this object baseItem wrapps a collection so we maybe could say it is almost a collection. The