Search Results

Search found 386 results on 16 pages for 'subclasses'.

Page 2/16 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • LockMode With Subclasses

    - by Lester
    I'm using Fluent Nhibernate with the following query on DerivedClass which extends BaseClass: var query = Session.CreateCriteria<DerivedClass>().SetLockMode(LockMode.Upgrade) What I want is the lock hints (updlock, rowlock) to be applied to both DerivedClass and BaseClass, but the generated SQL only applies the lock hints to DerivedClass: SELECT * FROM DerivedClass this_ with (updlock, rowlock) inner join [BaseClass] this_1_ on this_.Id=this_1_.Id WHERE ... This is the same situation described in http://opensource.atlassian.com/projects/hibernate/browse/HHH-2392 If anyone could point me in the right direction it would be much appreciated.

    Read the article

  • Java generic Comparable where subclasses can't compare to eachother

    - by dege
    public abstract class MyAbs implements Comparable<MyAbs> This would work but then I would be able to compare class A and B with each other if they both extend MyAbs. What I want to accomplish however is the exact opposite. So does anyone know a way to get the generic type to be the own class? Seemed like such a simple thing at first... Edit: To explain it a little further with an example. Say you have an abstract class animals, then you extend it with Dogs and ants. I wouldn't want to compare ants with Dogs but I however would want to compare one dog with another. The dog might have a variable saying what color it is and that is what I want to use in the compareTo method. However when it comes to ants I would rather want to compare ant's size than their color. Hope that clears it up. Could possibly be a design flaw however.

    Read the article

  • How to handle subclasses in JasperReports?

    - by gotch4
    I've two classes (A and B) that extend a base class BASE. I need to make a report that takes an array of such classes and the prints the fields of A or B. I tought of using conditional expressions, then casting to one or another (depending on a field value). But I can't cast, because I don't know how to refere to the current bean. To do this I am using a JRBeanCollectionDataSource filled with a List<BASE>. How do I cast every bean to A or B in a report (or subreport)? I tried: ((A)this) but it says basically that this contains the report instance, not the current bean and gives error.

    Read the article

  • Cyclic Reference - protocols and subclasses

    - by blindJesse
    I'm getting some cyclic reference (I think) problems between a few classes that require imported headers due to either subclassing or protocol definitions. I can explain why things are set up this way but I'm not sure it's essential. Basically these classes are managing reciprocal to-many data relationships. The layout is this: Class A imports Class B because it's a delegate of Class B and needs its protocol definition. Class B imports Class C because it's a subclass of Class C. Class C imports Class A because it's a delegate of Class A and needs its protocol definition. Here's some sample code that illustrates the problem. The errors I'm getting are as follows: In Class A - "Can't find protocol definition for Class_B_Delegate". In Class B - "Can't find interface declaration for Class C - superclass of Class B." In Class C - "Can't find protocol definition for Class_A_Delegate". Class A header: #import <Foundation/Foundation.h> #import "Class_B.h" @protocol Class_A_Delegate @end @interface Class_A : NSObject <Class_B_Delegate> { } @end Class B header: #import <Foundation/Foundation.h> #import "Class_C.h" @protocol Class_B_Delegate <NSObject> @end @interface Class_B : Class_C { } @end Class C Header: #import <Foundation/Foundation.h> #import "Class_A.h" @interface Class_C : NSObject <Class_A_Delegate> { } @end

    Read the article

  • Nullpointerexcption & abrupt IOStream closure with inheritence and subclasses

    - by user1401652
    A brief background before so we can communicate on the same wave length. I've had about 8-10 university courses on programming from data structure, to one on all languages, to specific ones such as java & c++. I'm a bit rusty because i usually take 2-3 month breaks from coding. This is a personal project that I started thinking of two years back. Okay down to the details, and a specific question, I'm having problems with my mutator functions. It seems to be that I am trying to access a private variable incorrectly. The question is, am I nesting my classes too much and trying to mutate a base class variable the incorrect way. If so point me in the way of the correct literature, or confirm this is my problem so I can restudy this information. Thanks package GroceryReceiptProgram; import java.io.*; import java.util.Vector; public class Date { private int hour, minute, day, month, year; Date() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What's the hour? (Use 1-24 military notation"); hour = Integer.parseInt(keyboard.readLine()); System.out.println("what's the minute? "); minute = Integer.parseInt(keyboard.readLine()); System.out.println("What's the day of the month?"); day = Integer.parseInt(keyboard.readLine()); System.out.println("Which month of the year is it, use an integer"); month = Integer.parseInt(keyboard.readLine()); System.out.println("What year is it?"); year = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (IOException e) { System.out.println("Yo houston we have a problem"); } } public void setHour(int hour) { this.hour = hour; } public void setHour() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What hour, use military notation?"); this.hour = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString()); } } public int getHour() { return hour; } public void setMinute(int minute) { this.minute = minute; } public void setMinute() { try (BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in))) { System.out.println("What minute?"); this.minute = Integer.parseInt(keyboard.readLine()); } catch (NumberFormatException e) { System.out.println(e.toString() + ": doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString() + ": minute shall not cooperate"); } catch (NullPointerException e) { System.out.println(e.toString() + ": in the setMinute function of the Date class"); } } public int getMinute() { return minute; } public void setDay(int day) { this.day = day; } public void setDay() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What day 0-6?"); this.day = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString()); } } public int getDay() { return day; } public void setMonth(int month) { this.month = month; } public void setMonth() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What month 0-11?"); this.month = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString()); } } public int getMonth() { return month; } public void setYear(int year) { this.year = year; } public void setYear() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What year?"); this.year = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString()); } } public int getYear() { return year; } public void set() { setMinute(); setHour(); setDay(); setMonth(); setYear(); } public Vector<Integer> get() { Vector<Integer> holder = new Vector<Integer>(5); holder.add(hour); holder.add(minute); holder.add(month); holder.add(day); holder.add(year); return holder; } }; That is the Date class obviously, next is the other base class Location. package GroceryReceiptProgram; import java.io.*; import java.util.Vector; public class Location { String streetName, state, city, country; int zipCode, address; Location() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What is the street name"); streetName = keyboard.readLine(); System.out.println("Which state?"); state = keyboard.readLine(); System.out.println("Which city?"); city = keyboard.readLine(); System.out.println("Which country?"); country = keyboard.readLine(); System.out.println("Which zipcode?");//if not u.s. continue around this step zipCode = Integer.parseInt(keyboard.readLine()); System.out.println("What address?"); address = Integer.parseInt(keyboard.readLine()); } catch (IOException e) { System.out.println(e.toString()); } } public void setZipCode(int zipCode) { this.zipCode = zipCode; } public void setZipCode() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What zipCode?"); this.zipCode = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString()); } } public void set() { setAddress(); setCity(); setCountry(); setState(); setStreetName(); setZipCode(); } public int getZipCode() { return zipCode; } public void setAddress(int address) { this.address = address; } public void setAddress() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What minute?"); this.address = Integer.parseInt(keyboard.readLine()); keyboard.close(); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString()); } } public int getAddress() { return address; } public void setStreetName(String streetName) { this.streetName = streetName; } public void setStreetName() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What minute?"); this.streetName = keyboard.readLine(); keyboard.close(); } catch (IOException e) { System.out.println(e.toString()); } } public String getStreetName() { return streetName; } public void setState(String state) { this.state = state; } public void setState() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What minute?"); this.state = keyboard.readLine(); keyboard.close(); } catch (IOException e) { System.out.println(e.toString()); } } public String getState() { return state; } public void setCity(String city) { this.city = city; } public void setCity() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What minute?"); this.city = keyboard.readLine(); keyboard.close(); } catch (IOException e) { System.out.println(e.toString()); } } public String getCity() { return city; } public void setCountry(String country) { this.country = country; } public void setCountry() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What minute?"); this.country = keyboard.readLine(); keyboard.close(); } catch (IOException e) { System.out.println(e.toString()); } } public String getCountry() { return country; } }; their parent(What is the proper name?) class package GroceryReceiptProgram; import java.io.*; public class FoodGroup { private int price, count; private Date purchaseDate, expirationDate; private Location location; private String name; public FoodGroup() { try { setPrice(); setCount(); expirationDate.set(); purchaseDate.set(); location.set(); } catch (NullPointerException e) { System.out.println(e.toString() + ": in the constructor of the FoodGroup class"); } } public void setPrice(int price) { this.price = price; } public void setPrice() { try (BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in))) { System.out.println("What Price?"); price = Integer.parseInt(keyboard.readLine()); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString() + ": in the FoodGroup class, setPrice function"); } catch (NullPointerException e) { System.out.println(e.toString() + ": in FoodGroup class. SetPrice()"); } } public int getPrice() { return price; } public void setCount(int count) { this.count = count; } public void setCount() { try (BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in))) { System.out.println("What count?"); count = Integer.parseInt(keyboard.readLine()); } catch (NumberFormatException e) { System.out.println(e.toString() + ":doesnt seem to be a number"); } catch (IOException e) { System.out.println(e.toString() + ": in the FoodGroup class, setCount()"); } catch (NullPointerException e) { System.out.println(e.toString() + ": in FoodGroup class, setCount"); } } public int getCount() { return count; } public void setName(String name) { this.name = name; } public void setName() { try { BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); System.out.println("What minute?"); this.name = keyboard.readLine(); } catch (IOException e) { System.out.println(e.toString()); } } public String getName() { return name; } public void setLocation(Location location) { this.location = location; } public Location getLocation() { return location; } public void setPurchaseDate(Date purchaseDate) { this.purchaseDate = purchaseDate; } public void setPurchaseDate() { this.purchaseDate.set(); } public Date getPurchaseDate() { return purchaseDate; } public void setExpirationDate(Date expirationDate) { this.expirationDate = expirationDate; } public void setExpirationDate() { this.expirationDate.set(); } public Date getExpirationDate() { return expirationDate; } } and finally the main class, so I can get access to all of this work. package GroceryReceiptProgram; public class NewMain { public static void main(String[] args) { FoodGroup test = new FoodGroup(); } } If anyone is further interested, here is a link the UML for this. https://www.dropbox.com/s/1weigjnxih70tbv/GRP.dia

    Read the article

  • STI and subclasses

    - by markiv
    Hi All, I want to know, what is a rails way of converting a subclass record to another subclass record, just changing type isn't working and also superclass to subclass and vice versa. Thanks in advance Markiv

    Read the article

  • iPhone: Helpful Classes or extended Subclasses which should have been in the SDK

    - by disp
    This is more a community sharing post than a real question. In my iPhone OS projects I'm always importing a helper class with helpful methods which I can use for about every project. So I thought it might be a good idea, if everyone shares some of their favorite methods, which should have been in everyones toolcase. I'll start with an extension of the NSString class, so I can make strings with dates on the fly providing format and locale. Maybe someone can find some need in this. @implementation NSString (DateHelper) +(NSString *) stringWithDate:(NSDate*)date withFormat:(NSString *)format withLocaleIdent:(NSString*)localeString{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; //For example @"de-DE", or @"en-US" NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localeString]; [dateFormatter setLocale:locale]; // For example @"HH:mm" [dateFormatter setDateFormat:format]; NSString *string = [dateFormatter stringFromDate:date]; [dateFormatter release]; [locale release]; return string; } @end I'd love to see some of your tools.

    Read the article

  • validate uniqueness amongst multiple subclasses with Single Table Inheritance

    - by irkenInvader
    I have a Card model that has many Sets and a Set model that has many Cards through a Membership model: class Card < ActiveRecord::Base has_many :memberships has_many :sets, :through => :memberships end class Membership < ActiveRecord::Base belongs_to :card belongs_to :set validates_uniqueness_of :card_id, :scope => :set_id end class Set < ActiveRecord::Base has_many :memberships has_many :cards, :through => :memberships validates_presence_of :cards end I also have some sub-classes of the above using Single Table Inheritance: class FooCard < Card end class BarCard < Card end and class Expansion < Set end class GameSet < Set validates_size_of :cards, :is => 10 end All of the above is working as I intend. What I'm trying to figure out is how to validate that a Card can only belong to a single Expansion. I want the following to be invalid: some_cards = FooCard.all( :limit => 25 ) first_expansion = Expansion.new second_expansion = Expansion.new first_expansion.cards = some_cards second_expansion.cards = some_cards first_expansion.save # Valid second_expansion.save # **Should be invalid** However, GameSets should allow this behavior: other_cards = FooCard.all( :limit => 10 ) first_set = GameSet.new second_set = GameSet.new first_set.cards = other_cards # Valid second_set.cards = other_cards # Also valid I'm guessing that a validates_uniqueness_of call is needed somewhere, but I'm not sure where to put it. Any suggestions? UPDATE 1 I modified the Expansion class as sugested: class Expansion < Set validate :validates_uniqueness_of_cards def validates_uniqueness_of_cards membership = Membership.find( :first, :include => :set, :conditions => [ "card_id IN (?) AND sets.type = ?", self.cards.map(&:id), "Expansion" ] ) errors.add_to_base("a Card can only belong to a single Expansion") unless membership.nil? end end This works when creating initial expansions to validate that no current expansions contain the cards. However, this (falsely) invalidates future updates to the expansion with new cards. In other words: old_exp = Expansion.find(1) old_exp.card_ids # returns [1,2,3,4,5] new_exp = Expansion.new new_exp.card_ids = [6,7,8,9,10] new_exp.save # returns true new_exp.card_ids << [11,12] # no other Expansion contains these cards new_exp.valid? # returns false ... SHOULD be true

    Read the article

  • Using custom Qt subclasses in Python

    - by kwatford
    First off: I'm new to both Qt and SWIG. Currently reading documentation for both of these, but this is a time consuming task, so I'm looking for some spoilers. It's good to know up-front whether something just won't work. I'm attempting to formulate a modular architecture for some in-house software. The core components are in C++ and exposed via SWIG to Python for experimentation and rapid prototyping of new components. Qt seems like it has some classes I could use to avoid re-inventing the wheel too much here, but I'm concerned about how some of the bits will fit together. Specifically, if I create some C++ classes, I'll need to expose them via SWIG. Some of these classes likely subclass Qt classes or otherwise have Qt stuff exposed in their public interfaces. This seems like it could raise some complications. There are already two interfaces for Qt in Python, PyQt and PySide. Will probably use PySide for licensing reasons. About how painful should I expect it to be to get a SWIG-wrapped custom subclass of a Qt class to play nice with either of these? What complications should I know about upfront?

    Read the article

  • Rails before_filter on subclasses beeing called twice

    - by rubenfonseca
    Hi! I'm at Rails 2.3.5 and I have this problem: class BaseController < ApplicationController before_filter :foo, :only => [:index] end class ChildController < BaseController before_filter :foo, :only => [:index, :show, :other, :actions] end The problem is that on ChildController, the :foo before filter gets called twice. I've tried a number of workarounds around this problem. If I don't include the :index action on the child, it never gets called for that action. The solution I found works, but is very very ugly skip_before_filter :foo before_filter :foo, :only => [:index, :show, :other, :actions] Is there a better way to solve this problem? Thanks

    Read the article

  • how to organize classes in ruby if they are literal subclasses

    - by RetroNoodle
    I know that title didn't make sense, Im sorry! Its hard to word what I am trying to ask. I had trouble googling it for the same reason. So this isn't even Ruby specific, but I am working in ruby and I am new to it, so bear with me. So you have a class that is a document. Inside each document, you have sentences, and each sentence has words. Words will have properties, like "noun" or a count of how many times they are used in the document, etc. I would like each of the elements, document, sentence, word be an object. Now, if you think literally - sentences are in documents, and words are in sentences. Should this be organized literally like this as well? Like inside the document class you will define and instantiate the sentence objects, and inside the sentence class you will define and instantiate the words? Or, should everything be separate and reference each other? Like the word class would sit outside the sentence class but the sentence class would be able to instantiate and work with words? This is a basic OOP question I guess, and I suppose you could argue to do it either way. What do you guys think? Each sentence in the document could be stored in a hash of sentence objects inside the document object, and each word in the sentence could be stored in a hash of word objects inside the sentence. I dont want to code myself into a corner here, thats why I am asking, plus I have wondered this before in other situations. Thank you!

    Read the article

  • Mutate an object into an instance of one its subclasses

    - by Gohu
    Hi, Is it possible to mutate an object into an instance of a derived class of the initial's object class? Something like: class Base(): def __init__(self): self.a = 1 def mutate(self): self = Derived() class Derived(Base): def __init__(self): self.b = 2 But that doesn't work. >>> obj = Base() >>> obj.mutate() >>> obj.a 1 >>> obj.b AttributeError... If this isn't possible, how should I do otherwise? My problem is the following: My Base class is like a "summary", and the Derived class is the "whole thing". Of course getting the "whole thing" is a bit expensive so working on summaries as long as it is possible is the point of having these two classes. But you should be able to get it if you want, and then there's no point in having the summary anymore, so every reference to the summary should now be (or contain, at least) the whole thing. I guess I would have to create a class that can hold both, right? class Thing(): def __init__(self): self.summary = Summary() self.whole = None def get_whole_thing(self): self.whole = Whole()

    Read the article

  • managed object subclasses are not generating implementation files and are incorrectly named

    - by mkc842
    In Xcode 4.6, I generated plenty of managed object subclass files without any problem. But now that I'm trying to do it in Xcode 5, it generates only a .h file. The header file has the correct properties, but it takes the name of my project, rather than the name of the core data entity I selected. Just to be sure I hadn't forgotten something, I carefully followed these steps . What could be going on? Thanks

    Read the article

  • What class structure allows for a base class and mix/match of subclasses? (Similar to Users w/ roles)

    - by cdeszaq
    I have a set of base characteristics, and then a number of sub-types. Each instance must be one of the sub-types, but can be multiple sub-types at once. The sub-types of each thing can change. In general, I don't care what subtype I have, but sometimes I do care. This is much like a Users-Roles sort of relationship where a User having a particular Role gives the user additional characteristics. Sort of like duck-typing (ie. If my Foo has a Bar, I can treat it like a ThingWithABar.) Straight inheritance doesn't work, since that doesn't allow mix/match of sub-types. (ie. no multi-inheritance). Straight composition doesn't work because I can't switch that up at runtime. How can I model this?

    Read the article

  • JPanel superclass doesn't add the components of its subclasses..

    - by Acryl
    Well, I use a JFrame that adds two JPanels. Those JPanels are superclasses, because I find it easier to separate different areas of the GUI into different classes. But here's the problem: I add the (superclass) JPanel to the JFrame I set the layout of the superclass JPanel to new BorderLayout(); I add components in the subclasses, like this: JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2,1)); panel.add(new JLabel("Label:"); panel.add(new JTextField(); add(panel, BorderLayout.NORTH); But it doesn't show. What do I do wrong? I've tried it without an additional JPanel in the subclasses, but it doesn't work either. I use jdk 1.6

    Read the article

  • Do I need to override the writing methods of NSDocument in subclasses for an application that will o

    - by Abizern
    I think I may be missing the obvious but I'm not sure. The section on subclassing NSDocument in the docs states that subclasses of NSDocument must override one reading and one writing method. If I'm creating a viewer application that will not write anything back, do I still need to override a writing method (returning what, nil?) or can I ignore it and make sure that there are no saving methods that can get called?

    Read the article

  • How do you use the LINQ to SQL designer to generate accessor methods for subclasses?

    - by Pricey
    Above is the LINQ to SQL designer view for my data context. Below is the relevant code: public System.Data.Linq.Table<ActivityBase> ActivityBases { get { return this.GetTable<ActivityBase>(); } } ... [Table(Name="dbo.Activities")] [InheritanceMapping(Code="1", Type=typeof(ActivityBase), IsDefault=true)] [InheritanceMapping(Code="2", Type=typeof(Project))] [InheritanceMapping(Code="3", Type=typeof(ProjectActivity))] [InheritanceMapping(Code="5", Type=typeof(Task))] [InheritanceMapping(Code="4", Type=typeof(Activity))] public abstract partial class ActivityBase : INotifyPropertyChanging, INotifyPropertyChanged { ... Is there a way to generate accessor methods for the subclasses as shown in the inheritance mapping above (Project, Task, etc...) without doing it manually? I added them manually but then a change in the designer overwrites any manual changes. Am i doing this wrong? should I not be making accessors for the sub classes? filtering from ActivityBase seems worse to me. Thanks for any help on this.

    Read the article

  • How are java.lang.Object's protected methods protected from subclasses?

    - by Adrian Lang
    The keyword protected grants access to classes in the same package and subclasses (http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html). Now, every class has java.lang.Object as superclass (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html). Hence I conclude that every class may access java.lang.Object's methods even if they are protected. Take a look at the following example: public class Testclass { public Object getOne() throws CloneNotSupportedException { return this.clone(); } public Object getTwo() throws CloneNotSupportedException { return ((Object) this).clone(); } } While getOne() compiles fine, getTwo() gives Testclass.java:6: clone() has protected access in java.lang.Object return ((Object) this).clone(); I neither understand why getTwo() doesn't compile nor what's the difference (regarding the access of java.lang.Objects members) with getOne().

    Read the article

  • Ways to make (relatively) safe assumptions about the type of concrete subclasses?

    - by Kylotan
    I have an interface (defined as a abstract base class) that looks like this: class AbstractInterface { public: bool IsRelatedTo(const AbstractInterface& other) const = 0; } And I have an implementation of this (constructors etc omitted): class ConcreteThing { public: bool IsRelatedTo(const AbstractInterface& other) const { return m_ImplObject.has_relationship_to(other.m_ImplObject); } private: ImplementationObject m_ImplObject; } The AbstractInterface forms an interface in Project A, and the ConcreteThing lives in Project B as an implementation of that interface. This is so that code in Project A can access data from Project B without having a direct dependency on it - Project B just has to implement the correct interface. Obviously the line in the body of the IsRelatedTo function cannot compile - that instance of ConcreteThing has an m_ImplObject member, but it can't assume that all AbstractInterfaces do, including the other argument. In my system, I can actually assume that all implementations of AbstractInterface are instances of ConcreteThing (or subclasses thereof), but I'd prefer not to be casting the object to the concrete type in order to get at the private member, or encoding that assumption in a way that will crash without a diagnostic later if this assumption ceases to hold true. I cannot modify ImplementationObject, but I can modify AbstractInterface and ConcreteThing. I also cannot use the standard RTTI mechanism for checking a type prior to casting, or use dynamic_cast for a similar purpose. I have a feeling that I might be able to overload IsRelatedTo with a ConcreteThing argument, but I'm not sure how to call it via the base IsRelatedTo(AbstractInterface) method. It wouldn't get called automatically as it's not a strict reimplementation of that method. Is there a pattern for doing what I want here, allowing me to implement the IsRelatedTo function via ImplementationObject::has_relationship_to(ImplementationObject), without risky casts? (Also, I couldn't think of a good question title - please change it if you have a better one.)

    Read the article

  • Is there any reason why we don't use subclasses of UIImageView ?

    - by gotye
    Hey everyone, I am currently trying to create a subclass of UIImageView in order to make it download its image from server asynchronously ;) I tried to do it by myself but I haven't gone very far yet :D Anyway, I looked around here and found this : AsyncImageDownload I had a look at the code and the first which springs to mind is : why subclassing a UIView and not a UIImageView ?!? Any thoughts ? Cheers mates, Gotye.

    Read the article

  • In C#, can I hide/modify accessors in subclasses?

    - by Diego
    I'm not even sure what this principle is called or how to search for it, so I sincerely apologize if it has been brought up before, but the best way to do it is with an example. class Properties { public string Name { get; set; } } class MyClass { class SubProperties: Properties { public override Name { get { return GetActualName(); } set { _value = SetActualName(value); } } } public SubProperties ClassProperties; private GetActualName() { ClassProperties.Name = "name"; } private SetActualName(string s) { ClassProperties.Name = SomeOtherFunction(s); } } The idea is to have any object that instantiates MyClass have a fully accessible property ClassProperties. To that object, it would look exactly like a Properties object, but behind the scenes, MyClass is actually computing and modifying the results of the fields. This method of declaration is obviously wrong since I can't access GetActualName() and SetActualName() from within the SubProperties definition. How would I achieve something like this?

    Read the article

  • Is it possible to establish default values for inherited fields in subclasses?

    - by Christian Mann
    I'm trying to establish a default value for inherited fields from superclasses. So, my class hierarchy is thus: Character - Enemy - Boss                 \                   - Hero Each Character has a public static char avatar to represent him on an ASCII playing field. How do I set a default value for the avatar of each class inherited from Character? Thank you!

    Read the article

  • In Python, how to make data members visible to subclasses if not known when initializing an object ?

    - by LB
    The title is a bit long, but it should be pretty straightforward for someone well-aware of python. I'm a python newbie. So, maybe i'm doing things in the wrong way. Suppose I have a class TreeNode class TreeNode(Node): def __init__(self, name, id): Node.__init__(self, name, id) self.children = [] and a subclass with a weight: class WeightedNode(TreeNode): def __init__(self,name, id): TreeNode.__init__(self, name, id) self.weight = 0 So far, i think I'm ok. Now, I want to add an object variable called father in TreeNode so that WeightedNode has also this member. The problem is that I don't know when initializing the object who is going to be the father. I set the father afterwards with this method in TreeNode : def set_father(self, father_node): self.father = father_node The problem is then when i'm trying to access self.father in Weighted: print 'Name %s Father %s '%(self.name, self.father.name) I obtain: AttributeError: WeightedNode instance has no attribute 'father' I thought that I could make father visible by doing something in TreeNode.__init__ but i wasn't able to find what. How can i do that ? Thanks.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >