In my own humble opinion, I think interfaces are underrated and underused in REALbasic. Same car, same guy at all three locations. I might drive to the bank for a little cash, then swing by the fast-food restaurant for a hamburger and cola, followed by a quick jaunt to the liquor store for an aperitif. As long as I am in my car, I can interact with things that have drive-up windows. From a practical perspective, it means that I can drive to all three locations and never have to get out of my car. As a consumer of hamburgers, liquor, and money (for hamburgers and liquor), I go to each place for entirely different reasons, but there is an advantage to my knowing that all three locations have drive-up windows. The point is that fast-food restaurants, banks, and liquor stores really don't have all that much in common, other than the drive-up window. At least they did when I lived in Texas-at that time the drinking age was 19, and as a 19-year-old living in Texas, I thought that drive-up liquor stores were a very clever idea. I said that the fast-food restaurant was encapsulated because I only had three touch points where I interacted with it, even though a whole lot happened between the time I placed my order and picked up my order.įast-food restaurants aren't the only places that use the drive-up window "interface." Banks use them, too. The fast-food restaurant I was thinking about when I wrote that example had three points of interaction for me: the first was the menu and speaker where I placed my order, the second was the first window, where I paid, and the third was the second window where I picked up my order. When I talked about encapsulation, I used the fast-food restaurant drive-up window as an example. In the immediate sense, at least, code reuse isn't the object of this activity, but as you will see, it does make it possible to streamline the code that interacts with objects that share the same interface, which is why it can be so helpful. When this is the case, no code is shared. This task involves defining the interface itself and then modifying to classes to indicate that they both implement this common interface. If two class share a common set of methods, it is possible to link these two classes together by saying they share a common interface. At the same time, it's convenient to formally establish this relationship so that the different objects can be used in similar contexts. There are some cases when you have two objects (or classes) that are related and that perform the same tasks, but they both do it in such a fundamentally different way that establishing the class/subclass relationship doesn't really buy you anything. Simply put, you don't have to write any new methods for the subclass to get the functionality resident in the superclass. The benefit to this, so the story goes, is that it enables code reuse. Although the subclass may optionally reimplement or override a method from the parent class, it doesn't have to reimplement any method unless it wants to modify what that method does. Nevertheless, when one class is a subclass of another, it shares all the same members with the parent class. Other languages, such as Objective-C, refer to a similar concept as a protocol. In REALbasic, an interface is used much in the same way that the term is used with Java. This is also one of those areas where the term is used differently in different programming languages. Interfaces are another means by which you encapsulate your program. When talking about Interfaces, you say that a class implements a particular Interface. With subclassing, one class can be a subclass of another. Interfaces are an alternative to subclassing. Interfaces and Component-Oriented Programming In this section I will review some relatively more advanced programming techniques you can use to extend the functionality of your REALbasic classes. REALbasic Cross-Platform Application Development
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |