When to split up code in OOP

C++, C#, Java, PHP, ect...
Post Reply
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

When to split up code in OOP

Post by Xaos »

So. I'm learning Java and I'm working on some practice stuff. I just have one issue. I get the concepts, I know the basic stuff, all of that good stuff. I just don't know when to split stuff up into different classes, methods, objects, etc. When exactly should you split something into a new object, or a new method, or a new class? I get it's something like this:


Class - Cabinet
Object - Big Cup, Little Cup
Method - Cabinet Open, Cabinet Close, Remove Big Cup, Remove Little Cup, Place Big Cup, Place Little Cup

So should all of those things be separated? Or should Add a Cup be one method with the options to do little or big with removing the same way? Are the methods similar to functions in PHP?

OR is all of this dumb and I should just code and find out? ;)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: When to split up code in OOP

Post by Jackolantern »

That looks about right to me :)

And yes, methods are just functions inside of classes.

But yes, the only way to really get a grip on it is to just work with it. It is all going to take practice :)
The indelible lord of tl;dr
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: When to split up code in OOP

Post by Chris »

OOP comes from the technical specification. It's a theory which helps translate use-cases to machine code.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Coding”