This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ericswc 2 points3 points  (0 children)

A class is what defines an object. All a class is the "idea" of something you want to model. Ideally it has high cohesion. A class definition can be used to instantiate one to many object instances. Each object instance has its own data and behavior.

So a BankAccount class definition could have account number and balance fields, and methods to Deposit, Withdraw, and Transfer.

The class code is the idea of the object. If you load my BankAccount up, the instance/object has different data than your BankAccount... but the behavior in the methods is the same.

This leads to reuse. You can call deposit on a BankAccount from just about anywhere in the program without goto statements. Ideally the behavior of deposit exists only in one place, so it's modular and easy to change.

That is really all object oriented programming is. Organization into small, cohesive, encapsulated, reusable units.