Iain Ritchie wrote:
I was hoping to get some feedback on best practices,..One of the things I was most interested in was that I made the Cart class an inner class of the Store class and I'm not sure if this is good practice or not as I am struggling to understand the benefits of inner classes and not sure if they are used much so wanted to experiment to find a use for them and this made sense as the when the cart is instantiated it automatically adds itself to the list of Carts belonging to the Store.
If you look at the Java™ Tutorials about nested classes, it says that there should be an intimate relationship between the nested class and the outer class. For example, if you have a “Complex Data Structure”, you can say that the Node is part of the Linked List. Or if you have an “Event Handling” class, that may only make sense inside another class. (Note that at least 50% of event handling classes from before Java8 can now be replaced by λ expressions.)Iain Ritchie wrote:. . . I made the Cart class an inner class of the Store class . . .
That's a pleasureIain Ritchie wrote:. . . thank you
I am afraid I think it will cause more confusion than help. Unless it is very well written.. . . studying more source code . . . would help demystify the workings of larger programmes.
Iain Ritchie wrote:... looking at things differently now and take more consideration into the objects and relationships between them and hoping this will better inform my code. ... I will start reading up and studying more source code as I think it would help demystify the workings of larger programmes.
Then leave it for a year and read the same book again. You will probably understand a lot more the second time. And the third time. And the fourth time. And etc.Junilu Lacar wrote:. . . Read up on design principles and code smells. . . .
bacon. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|