Help with class design / general software design

Hi again guys, quick question for anyone interested :slight_smile:

Was wondering if anyone knew of some good tutorials or material that teaches good program design, good OOP design techniques, or code architectural organization.

That being the planning and design of classes and class structure.

I am becoming very comfortable with the language now, but still struggling with the correct structure of java classes/programs.

I have been searching and all I can really find are tutorials on the actual building of classes and the such, none on the design aspect.

I hope I’m making sense, only had 2 hours sleep last night! :cranky: :slight_smile:

Well, good coding design can be found by just looking in the Java Tutorials. You really want to make sure you are using your tabs and spaces to organize basic functions into groups and comment so you know what your code does.

For Object Oriented Programming practices, you just want to make sure you are separating your functionality into separate classes so they can be used later on. It stresses not using static, but instead keeping code modular (or separate) meaning plenty of getters and setters.

For code architectural design, it largely depends on what you are designing for. The best advice for design is just to keep it simple and to the point. For games, it usually helps to design logic and graphics code separate from each other, where logic resides in an update function and graphics interact with logic in a render function. Depending on the amount of features you have and what you are building, design architecture grows with the amount of features.

But… since you are just beginning, it is probably not best to be dabbing in all these advanced techniques. You will learn all of these overtime if you just choose a simple game and try to design it. Like Pong, Breakout, or Tic-Tac-Toe (Noughts & Crosses). It will be a lot more valuable than a bunch of people talking in tutorials and you’ll probably learn plenty too.

What the previous poster said: experience is the best teacher. Beyond very expensive textbooks, there’s not a lot out there that covers design aspects, but one I can recommend is Head First Design Patterns which is a somewhat more modernized and streamlined take on the original. One thing I really need to stress about design patterns is that they are descriptive, not prescriptive. As in, they’re about naming and cataloging existing best practices, but you don’t want to force your program to use them if they’re not an obvious natural fit. Nothing’s worse than seeing a program unnecessarily blown up to use Facades of Factories of Strategies of Visitors of blahdeblah etc ad nauseum. But a program that uses patterns properly can be a thing of beauty.

Another really biblical text in the design area is Bertrand Meyer’s Object-Oriented Software Construction. Meyer loves to explain everything in terms of Eiffel, a language that frankly only continues to exist for Meyer’s books and papers, but most of the ideas in there should apply to any language.

What little theory OO has to offer is worth reviewing, and two in particular are:

  • Law of Demeter - Only talk to your “neighbor” interfaces
  • Liskov Substitution Principle - The difference between subtypes and subclasses
    (but remember that a subclass may add interfaces, so don’t take it too strictly)

Head First Design Patterns!!! I highly recommend this book :slight_smile:

Try to keep you classes small and your methods smaller :slight_smile:

Build the application one feature at a time and test as you go along.

Avoid big detailed designs which are just inflexible and ultimately not related to reality, no matter how good the class diagram looks.

What a great response!! Thank you so much, will definitely check out that material.

Thanks for the advice ra4king and ags1!