Procedural vs Object-Oriented


A Simple OO Class with One More Detail

public class SomeClass
{
    // Instance variable(s)
    private int[]  theData;

    // Constructor(s)
    public SomeClass()
    {
        // constructor code goes here
    }
    .
    .
    .

    /** Populate the data in some way. */
    public void populateData()
    {
        // code to populate theData instance variable goes here
        //   (e.g., might read it from a file) 
    }
    .
    .
    .

    /** Search for given value; return index. */
    public int search(int searchValue)
    {
        for ( int i = 0; i < theData.length; i++ )
        {
            if ( theData[i] == searchValue )
            {
                return i;
            }
        }
        return -1;
    }
    .
    .
    .
}

Alyce Brady, Kalamazoo College