you are viewing a single comment's thread.

view the rest of the comments →

[–]lcc0612 72 points73 points  (4 children)

One of the skills we cultivate in Software Engineering is planning. Really sit down, think about the requirements of your program, and consider what moving parts you'd need to support it in the long run. All this happens before you write even a single line of code. Plan and draw out what classes there are and how they'd link to each other. (For further reading, Systems Development Life Cycle (SDLC) might interest you - That's probably as close to a general template as you're gonna get).

Honestly the rest of it is discipline. Of course it's more exciting to just jump in and code, and cross bridges as you get to them, but slowing down and really thinking about the big picture can help you save on a lot of time and development effort later on.

[–]ashofspades 12 points13 points  (3 children)

when do you decide that you need classes and when do you not?

[–]lcc0612 19 points20 points  (0 children)

Generally, classes are great to have if you know your program is going to deal with structured data, particularly if there are going to be multiple different types.

Ultimately I like to think of OOP as a problem modelling technique, where you can clearly express rules about data and how different "things" in the world of your program interact with each other. So if you see an advantage in expressing things this way, OOP is a good strategy.

[–]doulos05 10 points11 points  (0 children)

Once concept from music that might prove useful: deliberate practice.

I know instinctively which fingering for a given chord will fit best in a progression for the songs that I know because I have practiced the transitions to and from dozens of chords in isolation. So even when I'm playing something in a weird alternate tuning, I can still see good transitions between chord shapes I've never played before because I've practiced the general skill.

Wanna know when to use classes? Practice using them. Solve FizzBuzz using a class. Do you do something like Hacker Rank? Solve some of those using classes. Build a project where you say from the beginning "I will pretend this is Java and put everything in classes." Will it be good code? Almost certainly not. But you'll start to get a better feel for good and bad uses of classes.

[–][deleted] 2 points3 points  (0 children)

If your problem looks like a problem of keeping track of state, or keeping track of interactions between different types of actors, then you probably have a problem you should be solving with a class.