I haven't coded in java for a long time, and after coding in C, I'm having issued organizing my code for OOP. More specifically I'm not sure when to create a new method, and when to create a new class, and when to just lump everything together.
Are there some general rules or guidelines on how it should be done?
Take a look at the SOLID principles.
EDIT (some more pointers):
You need a SOLID GRASP of some design principles.
To start small, take a look at these first:
When writing code, high maintainability should be your ultimate goal, and it's all about assigning responsibilities and separation of concerns.
First of all, never just lump everything together. Try to identify the objects first. Build a class for each object your program will work with. If you're building an application for truck drivers, you will need a class for the driver, the truck, the load he's hauling, there's really no limit to how far you can break these bigger objects down. As for the methods, a method handles an action for the object. Truck.Start() would start the truck. Drive() would start it driving, etc... Maybe the Drive method takes a Route object for an argument which contains the roads to drive on. In short, create a method when an object needs to do something and create a class when you want to deal with another type of object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With