Misc. Tips - Eastside-Catholic/Tutorial GitHub Wiki

  • 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.
      • For example, the following code saves us from having to add double pacmanDistance() to every type of ghost.
      • This also means if we decide to change double pacmanDistance(), we only need to change it in one place.
    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"