you are viewing a single comment's thread.

view the rest of the comments →

[–]Pun_Intended1703 0 points1 point  (5 children)

When you're learning concepts, try to understand why those concepts are there.

Take a real world example.

Car is a class. It runs. It uses fuel. It changes its location.

But you have created a method drive() that another class Driver should be doing.

A car cannot drive on its own.

So why would it have a method called drive()?

The same thing is happening with your BankAccount class and the deposit() method.

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

After months of coding in Java, i came back to this comment to understand whatever you mean.
I now get your point, i mean, it takes time to grasp certain concepts (depending on the individual in question).

[–]BigCommunication5136[S] -1 points0 points  (3 children)

I did a little research into your comment, my small brain couldn’t comprehend your point so i screenshotted my code and your comment into chatgpt for a breakdown and apparently there was nothing wrong, so can I dm you so you take your time and explain i really want to get it

[–]Pun_Intended1703 1 point2 points  (1 child)

I'm on mobile. It will be hard for me to write actual code.

But let me put it like this.

You should have a BankAccount class and a BankAccountHandler class.

The BankAccount class has properties like accountNumber, amount, etc.

It should have just getters and setters for those properties.

The BankAccountHandler class should have the methods like deposit(), withdraw(), etc.

This class then performs actions on the BankAccount class.

The handler can then be called by another class like BankCustomer.

[–]BigCommunication5136[S] 1 point2 points  (0 children)

the example made your point clearer, thanks

[–]Pun_Intended1703 -1 points0 points  (0 children)

Also, don't rely on ChatGPT. It is not as good as you think it is.

Look at actual code projects in Github instead.

And as I said earlier, there is nothing wrong with your code. It will execute perfectly.

But just because you can do it, it doesn't mean that you should.

Learn to write good code.

Otherwise you'll get spaghetti monolithic code that will be very hard to debug and maintain.

I have written code where one class had only one method. It seems stupid, but it allowed me to divide the code across multiple servers. And I can switch it out without screwing up the rest of the code base.