View Single Post
bassplayinMacFiend
Banging the Bottom End
 
Join Date: Jun 2004
 
2006-01-25, 20:15

First, let's try to define an object. Let's say an object is a collection of data and functions that work on said data. Let me try a simple example.

For my example, I will use book and library objects. The book will contain pertinent information about the book, and the library will be a collection of book objects.

So, a book object has the following data attributes:

BookName
ISBN
Author
Date
Publisher

The object will need gettor/settor methods to set/change and retrieve each data element from an object. For example a couple of book functions would be

public string bookName() {
return bookName;
}

public void setBookName(string bName) {
bookName = bName;
}

The idea behind OOP is encapsulation, everything related to an object is accessed through publicly defined functions. You don't just manipulate bookName directly, you use methods to get and set the bookName variable. The same applies to the other data elements, plus any object functionality you may add to the object.

Now let's move onto the library object. The library will contain a collection of book objects, because that's what a library is. But, in order to be useful, the library will need to keep track of whether or not a book is checked out, who checked a book out, whether a late fee is due. Also, a library will need to add newly purchased books to and removed damaged/destroyed/lost books from the library collection.

To do this, let's create a new inventory object. The inventory object contains the following data elements:

a Book object
inLibrary? boolean
dateDue (if not inLibrary)
lastCheckedOutBy (reference to person object)

Now the library object will have to manage the inventory collection.


I know you said you didn't like Java, but here's a library example I did in Java for a grant project in 2002 (paid for my 20GB iPod ). If you have any questions, I'll try to answer them, but it's been awhile. http://members.cox.net/pevac/ex8code.txt
  quote