Skip to content
andrewsentman edited this page Sep 4, 2015 · 3 revisions
  • If two people edit the same file, it creates a conflict when the branches are merged. This is difficult to resolve.

    • Code should be split into separate files as much as reasonable.
    • The main class should contain as little as possible.
  • Utility functions should be made static and placed into classes according to function.

    • Java does this well:
      • The Math class contains all math functions
      • System contains methods for dealing with the system
    • Example: In a gradebook program, all functions for displaying data should be in Display.java
  • Using inheritance can save a lot of work.

    • If there are several classes that do similar things, they should extend a parent class that contains the shared code.
      • Every type of ghost needs a method to calculate their distance from pacman: double pacmanDistance()
      • The code should look like this:
    class Ghost:
        double pacmanDistance():
            return 5
    class RedGhost extends Ghost:
        void beARedGhost():
            print "I am red and "+pacmanDistance()+" away from pacman"
    class RedGhost extends Ghost:
        void beAGreenGhost():
            print "I am green and "+pacmanDistance()+" away from pacman"
    class RedGhost extends Ghost:
        void beABlueGhost():
            print "I am blue and "+pacmanDistance()+" away from pacman"

Clone this wiki locally