100 likes | 255 Views
Object Oriented Programming. ICS3/4. Why OOP?. In the past, all of your programs have been “ procedural programs ” . Use loops, decision statements etc. to solve problems
E N D
Object Oriented Programming ICS3/4
Why OOP? • In the past, all of your programs have been “procedural programs”. • Use loops, decision statements etc. to solve problems • PROBLEM: It is not always easy to take real life situations and program them using simple variables (int, double, boolean, string) • The focus is on solving tasks
Why OOP? • Object Oriented programming is a new paradigm • We focus on data objects and relationships among them • Think of data as active – it does things (instead of having things done to it) • Your programs become a collect of objects that cooperate and share information between them • Eg. Several factories work together to make the parts for building a car
Classes • In OOP, classes are blueprints for creating objects • Defines what properties an object has • Defines what actions the object can perform or have performed on it • Classes define the way objects look and behave.
Lets look at a sample class • The fraction class • Instance variables • Private vs. public • Information hiding • The Constructor • Methods • Setter and getters
Why Use Objects? • Clarity • Reusability • Customizable • Create your own data types and control how they are used • Excellent for simulations of real life situations • Eg. Simulate the effects on traffic of shutting down the 401
Your task • Create a class for representing students in a school administration program • What properties does a student have? • What can it do? (in the context of our program) • Test your class by creating student objects and manipulating them