New topic: Base class or and interface.
<http://forums.realsoftware.com/viewtopic.php?t=31377> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message JustSomeGuy Post subject: Base class or and interface.Posted: Wed Dec 02, 2009 11:49 am Joined: Fri May 11, 2007 11:35 am Posts: 665 I have a group of object with an identical interface and computed properties. I thought I should make a class interface and then all my objects could use that interface. However I got stuck when it came to implementing the class interface and putting in the computed properties. Is it not possible to define computed properties in a class interface. Perhaps it would have been better to inherit from a base class? _________________ A picture paints a thousand words. A thought paints a thousand pictures. Top timhare Post subject: Re: Base class or and interface.Posted: Wed Dec 02, 2009 12:29 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 6867 Location: Portland, OR USA Properties, computed or not, are part of the implementation details. An interface should contain only the functional api and cannot (should not) include properties. It sounds like these classes are tightly coupled. Either rethink the relationships between the classes or use a common ancestor. Top Phil M Post subject: Re: Base class or and interface.Posted: Wed Dec 02, 2009 12:56 pm Joined: Fri Sep 30, 2005 12:18 pm Posts: 566 While you COULD use a Class Interface to access those properties (through getter/setter methods) you would have to implement those methods in each of the classes and it would likely be more trouble than its worth. For what you are describing, you might consider making a super class that those properties and computed properties are inherited from. Another option is to make a separate "data" class that contains those properties and all of the classes that use those properties have a Constructor (or init function) to initialize the data class. You could even have computed properties in each of your regular classes which directly access the data class properties making it appear seamless. Class Interfaces are best used for tasks where you have an unknown type of object which might be able to interact with set of code (API). For example, if you have a system which handles messages sent throughout your app, you might want to have one or more classes defined as listeners. Defining a class as a listener and "registering" that class with the messaging system will allow that system to notify each listener that a new message is available. An example of a message system is a Socket array handling the downloading of each file. You would "register" the Download window to receive progress for each download, and possibly other class(es) to be notified when the download has been completed. The class interface might have methods something like TransactionProgress and TransactionComplete. Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
