Object (computer science)

From Simple English Wikipedia, the free encyclopedia

In Object-oriented programming, an object is an instance of a Class. Objects are abstractly a collection of fields. Fields are like variables, with a name and a value. Fields can also be named functions, these fields are called methods. Fields are usually private, i.e. not visible outside the object. Instead private data is changed by using an interface, i.e. a bunch of methods.

Suppose there is a bank account; this bank account has a current balance, but it also has a history of things that were done. However these fields are private. Rather there are methods like deposit() and withdraw() and checkBalance(). Most applications (and other objects) only change this object through this interface.

Banks usually impose a credit limit. Suppose, there are 1000 dollars on the account. If the client does not have a special agreement with the bank, he cannot take out more money than there is on the account; so he can withdraw() a maximum of 1000 dollars. He might have an agreement with the bank, so he can borrow money from the bank (but has to pay a fee). In that case, he might be able to withdraw 1500 dollars (or 2000 dollars). So the withdraw method has to do a lot of checks as described above. The account manager might see the account differently, she might have methods to set the maximum amount that can be taken out of the account, or to set the fee or interest rate that the customer has to pay for the money to be borrowed.

As an object is an instance of a class; it has certain things from that class. It can perhaps be compared to other objects of that class. Two apples, one red and bigger, the other green and smaller. On the other hand: It is not that easy to compare different objects. A green apple does not have much in common with a steel wrench.

Related pages[change | change source]

Other websites[change | change source]