Before we begin...

Concepts and their implementation

  • The Computer Science education that you get in Emory provide you with fundamental understanding of computer science concepts

  • Sample concepts:

      • Parameter passing mechanisms

      • Variable scope and their scoping rules

      • Etc

  • The concepts were illustrated through the use of the Java programming language

    Example:

      • We showed the effect of the pass-by-value parameter passing mechanism

Some of the Computer Science concepts that you have learned so far...

  • Variables and data types

  • Basic understanding of the computer architecture, computer memory and reference (= memory address)

  • Operators (+, -, *, /, %) and statements (assignment, if, while)

  • Functions, parameters and function overloading:

      • Parameter passing mechanisms (pass-by-value, pass-by-reference)
      • Scoping rules of local variables

  • Basic data structures (arrays)


  • Important note:

    • Understand the concepts

      They are the same in every programming language

    • They are only expressed differently in different programming language...

Class: revisited

  • You have learned about a class in Java:

    • Class contains variables and methods

    Example:

    public class myClass
    {
        public static String message = "Hello";
    
        public static void main(String[] args)
        {
            System.out.println(message);
        }
    }

  • The real purpose of a class in Java is:

    • To implement/model an object that contribute to the solution of our problem

Writing complex computer programs

  • The material in the review section will allow you to solve many programming problems using selections (if, if-else), loops for, while), methods, and arrays.

  • However, these programming features are not sufficient for developing large-scale complex computer programs

  • Programming methodology before around 1980:

      • We use the modular programming technique to help build large-scale complex computer programs

  • Today's programming languages use:

      • The object concept to build large-scale complex computer programs

  • The style of programming using objects is called:

      • Object Oriented Programming (OOP)

How Object Oriented Programming (OOP) help you write complex programs

  • Abstraction: OOP provides abstract classes to help reduce (= hide) details

  • Inheritance: allows existing code to be re-used

  • Polymorphism: allows existing code to be modified/enhanced

  • Encapsulation: prevents code in other classes from accessing/modifying important variables to localize debugging

Object Oriented Programming (OOP)   what is an object ?

  • Object-oriented programming (OOP):

      • Uses objects to reduce complexity

        (i.e.: OOP is an abstraction technique)

  • An object represents an entity in the real world that can be distinctly identified.

  • Examples of objects:

      • a student (each student can be uniquely identified)
      • a circle (each circle can be uniquely identified)
      • ...

  • An object has:

      • A unique identity (you can tell different object apart)
      • A state            (discussed next)
      • A behavior     (discussed next)

The state of objects

  • The state of an object (also known as its properties or attributes) is represented by data fields with their current values.

    Examples:

      • A circle object has a data field radius, which is the property that characterizes a circle.

      • A rectangle object has the data fields width and height, which are the properties that characterize a rectangle.


  • A Java class represents the state/properties of objects using:

      • The instance variables (that we will study later) inside a class

      • Each object will have it's own instance variables

The behavior of objects

  • The behavior of an object (also known as its actions ) is defined by methods.

  • To invoke a method on an object is to "tell the object" to perform an action.

    Examples:

      • You can define methods named getArea() and getPerimeter() for circle objects.

      • Then:

          • invoking getArea() will instruct a circle to return its area
          • invoking getPerimeter() will instruct a circle to return its perimeter


  • A Java class defines the behavior of objects using:

      • The instance methods (that we will study later) inside a class

      • All objects of a class share the instance methods (because they have the same behavior)

The real purpose of classes in Java

  • Summary: a Java class defines the (1) properties and (2) behaviors for objects:

      • The instance variables in a (Java) class store the current values of the properties of an object

        • E.g.: radius of a circle object

      • The instance methods in a (Java) class defines the behavior/actions of the object

        • E.g.: getArea() of a circle object

  • A class is used as a template (= description) to construct the object's data fields and to define its methods:

      • When you create objects of a class, Java will use the class definition to allocate the instance variables for that object.

      • When you invoke some method on an object, Java will run the code in the method definition on the instance variables of the object

Objects and its class

  • An object is an instance created using a class definition.

      • (Remember that the class definition describes the properties (= instance variables) and behavior (= instance methods) of the object)

  • You can create as many instances (= objects) of a class as you need.

      • Each object will have its own properties (= instance variables)

      • But: all object will share the same actions (= instance methods)


  • Analogy to explain:     class and object:

      • Class = recipe to make apple pie

      • Object = some apple pie (e.g.: John's apply pie)