| You are here: | About>Computing & Technology>C / C++ / C#> Getting Started> Introduction to Object Oriented Programming |
![]() | C / C++ / C# |
Introduction to Object Oriented ProgrammingAn Overview of OOPImagine that we are writing an application to model a simple television. Our TV has the following controls that we need to handle.
Now in programming this, there are two ways to model a TV - the procedural approach in languages like C or Basic or the more modern OOP approach in C++, C# or Java. In the procedural approach we use variables to hold the TVs 'values'. A boolean on/off value, an integer number for the volume control and another for the channel. These values are accessible anywhere in our source code where it accesses the TVs variables. Its easy to introduce subtle bugs such as too large a number in the volume control or writing to the wrong variable. Think of the procedural approach as being as if our TV had no casing and that you had to use a screwdriver to change the volume or channel settings. It would be very dangerous! One slip and you might short something out. Accidentally changing a TV variable somewhere in your program could stop your program! With OOP, the controls are wrapped up inside a TV object and the only way to change them is by calling 'accessor' functions. Our TV now has a 'case' and you can only change the settings by toggling the on/off switch or changing the volume and channel controls. That's much safer to operate. This is known as encapsulation - putting everything inside a 'case' and limiting access. Our TV object has the following members. This is what it would look like in C++ syntax.
// private data, not publicly accessible |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | Print this Page | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


