Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Object-Oriented Programming (CITS2210) - Lab 3
Computer Science & Software Engineering
Object-Oriented Programming (CITS2210) - Lab 3
    |   |   |   | 

Using interfaces and emulating multiple inheritance.

  • Take your implementation for lab 2 and create interfaces for your classes for players, wumpuses and bumpuses.
  • Include a generic BoardPiece interface that all three extend.
  • Make the bumpus interface extend the player and wumpus interface- depending on how you've implemented the classes, some of these interfaces may in fact be the same, but we want to allow for future extensions. Alternatively, you also may find you need another interface for "attacking pieces" which both the player and bumpus interfaces extend.
  • Now, use inheritance as much as possible for the implementations in the corresponding classes. Avoid repeating code as much as possible. The bumpus class can only inherit from either the player class or the wumpus class - choose whichever seems better, probably the one from which the most methods are inherited.
  • At this point, you should have some methods that can't be inherited due to the lack of multiple inheritance in Java.
  • Instead of inheriting them, put an instance variable in the bumpus class that contains an instance of whichever class isn't inherited from.
  • Implement the methods that weren't inherited by simply having them call the methods on this instance variable. (This is called delegation.)
  • Consider the issues that occur now due to having two copies of instance variables like the x and y coordinates.
  • Resolve these issues by adding an instance variable called "useVars" to your BoardPiece class that is usually set to "this".
  • Modify your player or wumpus class (whichever isn't inherited) so that it accesses instance variables via "useVars" rather than directly.
  • Modify your bumpus class so that it sets this variable to the bumpus object when creating the sub-object.
  • Everything should work correctly now (perhaps with some more work to fit everything together) - we have full code reuse, but in one case it is done via delegation to a subobject rather than inheritance.

CRICOS Provider Code: 00126G