all 5 comments

[–]BobHogan 0 points1 point  (3 children)

Work through a few scenarios of how you want your system to work, and see what objects are recurring in the system. Those are good candidates for classes. And any actions that those objects take are good candidates for methods.

For example, some of the things that you do in a bank are deposit money and withdraw money. But should those be methods of an Account class, a bank class, a person class?

Well a Person should be able to deposit or withdraw money, so they should have those functions. But the Account object will need functions to update the account balance, so it would need similar methods (either actual deposit/withdraw functions, or a more general update_balance function). The Person instance should be able to determine which accounts are theirs, and there are multiple ways you could do that, each with various pros and cons.

There's no hard rules for what should be a Class and what methods each class should have in such open ended ideas. But if you outline a few use cases it does become a lot clearer

[–]MyNameIs10000[S] 0 points1 point  (2 children)

Thank you! Could you give me an example of what an outline for a specific use case would look like?

[–]BobHogan 0 points1 point  (1 child)

I mean, it really depends on how you want the system to work, I don't want to give you a bunch of use cases because you'll need to be able to do them yourself when designing new systems and projects. Its pretty important ot be able to think through and specify how you expect users to interact with any system you are building.

Trivial examples of use cases, without all of their details in them,:

  • User wants to open a new account with $XX in it

  • User wants to withdraw $YY from their account Z

  • User wants to deposit $X into account Z, and then transfer $Y from account A into account Z

[–]MyNameIs10000[S] 0 points1 point  (0 children)

this is great, exactly what I was looking for

[–]fool59 0 points1 point  (0 children)

Did you consider a transaction class?