Can somebody please explain me clearly by using some nice examples how c++ class is useful and why it is a good programming practice. I read a lot about class, did some programming in c++ using some classes but still I couldn’t be clear why class are needed and how would they make the code more robust and readable.
Thanks!!!!!
When you type a script or 20 lines of code or 100 lines of code it’s no big deal.
When you get to millions, you start to need a way to actually visualize your code. You need to be able to talk of different sections and how they interact.
When you look at a long procedure, how is it organized? When you have 20 functions, which ones correspond to what data? Now document and remember it so the next time you look at the code you’ll be able to get back to where you were right away.
Objects allow you to group functionality with the data it relates to. It lets you find the functionality you need quickly. Once you are used to it, it’s hard to imagine why you would code without it. I’m not sure how you’d diagram a design to show it to someone else without OO–Flow charts? Really?
If you design your non-OO code Very Well with private variables (private to this file) and functions that relate to that data you can get some of this organizational effect, but it’s messy and there is a lot of overhead. Plus it’s very easy for someone who doesn’t quite “Get” OO to send the entire codebase spiraling to code-hell.
It’s a very comfortable, logical sensible way to organize your code and data.