I have around 6 years of experience in the software Industry and 5+ years of experience in Java. During this period I have come across many freshers who are just starting their career in Java and ready to dive into the world of Object Orientation.
However I noticed the trend that they tend to quickly jump into coding their solution before evaluating the language and end up writing some code in Java which is exactly like C except the syntax.
Don't dive into code the solution as soon as you get the problem. Before writing any complex program, implement many simple problems object orientedly. Play around with Interface, Inheritance. See how dynamic polymorphism works at run time as it's a very powerful concept in Java.
Try to use Interfaces instead of concrete objects as much as possible and give a deeper look at the HAS-A property. If you are finding that you are writing many ifs and elses then look into your design closely once again. Try to think everything in terms of objects and how to make a communication among them.
For example - if you have to design a online Library, think what are the key objects needed. A library should have Books, Readers etc. Readers should be able to subscribe to the library so that they can stay updated with the latest collection. They should also be able unsubscribe if they want.
The Library should know about it's readers so that it can update them. It should also know about what are the books it has. There should also be a mechanism to quickly search for a book and it's status - like if it's available or some reader is already associated with it.
So, you can have a library Interface from which you can create concrete Libraries. Similarly you can have a Reader Interface to create concrete readers etc.
A concrete Library class should also have a list of readers, concrete Reader class should have a notify() method, so that the Library object can scan through the Reader object list and notify each reader object using the notify() method.
A concrete Reader class should also know the Library object to which it has subscribed. The Library class should have a subscribe() method and a unsubscribe() method so that the Reader can use it's Library object to get itself subscribed/unsubscribed to the Library.
So, the skeleton looks like below
This is just a simple example. You can see for yourself how to fit in the Book class. So, the idea is - before writing a single line of code, use the whiteboard extensively to come out with the design first.
All problems look simple at first and you will have the adrenaline rush to code it asap and get as much brownie points as you can get. But try to dominate that temptation and carefully think about the design.
Last but not the least , always remember - In software Industry SPECIFICATION WILL ALWAYS CHANGE . So, you have to think well in advance to make your code flexible to any specification change in future. Best of luck.
Sharing is Caring!
RECOMMENDED POSTS FOR YOU