functions, classes, etc. • Identifiers (name of variables and classes) are Nouns • Methods are Verbs • Avoid using misleading or cryptic names. • Follow consistent naming conventions. 10
something is done, not what is done. • Keep comments up to date with code changes. • Document public APIs and complex logic thoroughly. • Single Line vs Multiple Line (and JavaDoc) comments 11
and only one, job. • Keep functions focused on a single task. • Break down your code into smaller, reusable modules or functions. • Ensure each module or function has a clear, well-defined purpose. • 14
on) are provided externally rather than created internally by the object itself. • Constructor injection: Dependencies are passed via the class constructor. • Setter injection: Dependencies are provided through setter methods. • Make components more accessible to swap or extend without modifying the dependent class. 23
main(String[] arg) { View view = new View (); Player player = new Player(view); Game game = new Game(view); game.ready(); do { player.move(); game.move(); } while (!game.isOver()); game.bye(); } }
main(String[] arg) { View view = new View (); Player player = new Player(view); Game game = new Game(view); game.ready(); do { player.move(); game.move(); } while (!game.isOver()); game.bye(); } } public class View { public void print(String s) { System.out.println(s); } } public class Game { View myView; public Game(View v) { myView = v; } public void ready() { myView.print (“Welcome!”); } // more code … }
[email protected] Summer 2025 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.