A lot of what a program works with can be logically grouped as “objects”, or even just “things”. While keeping data stored in records with known fields (eg: a “person” may have a name, date of birth, etc) is nothing interesting, “object oriented programming” usually allows each type/category of object to do 2 major things:
1. Code can be written designed to be part of the object itself. This is often used to make sure the object is used properly and help minimize the risk of mistakes.
2. New object types can be created as a variant of an existing type. For example your “Person” type could be expanded into “Child” and “Adult”, or “Male” and “Female” variants, etc. They all still have names and dates of birth. But there are differences between them that the code should take care of when applicable, and in any case you can still treat them as each being a “Person” as usual.
Object oriented programming stresses the use of these styles and strategies of programming.
Want to add encrypted network communication? Take your “TCP_Connection” type and make a new version called “SSL_TCP_Connection”, then just use that any time you would use your original connection. If you did it right, it will just work and you can just pick which connection type you need when you create it and just roll with it from there.
Making a video game and adding a new monster type? Chances are it’ll be a variation of some generic monster, or a generic monster that can walk, or a generic monster with a weapon, or both.
Latest Answers