290 likes | 426 Views
COP3502: Introduction to CIS I. Lecture 8. i mperative programming. o bject-oriented programming. o bjects b uilding blocks of a program c ooperate to complete a task by sending messages. o bjects model tangible things c ars, schools, dogs . o bjects model conceptual things
E N D
COP3502: Introduction to CIS I Lecture 8
objects building blocks of a program cooperate to complete a task by sending messages
objects model tangible things cars, schools, dogs
objects model conceptual things an event, a job
objects model processes finding a path through a maze sorting a deck of cards
using already made objects String Math Integer Array
objects class “fancy variable”
objects properties (“things that describe it”) capabilities (“things it can do”)
capabilities (“behavior”) constructor – initialize object command – change an object’s properties query – send an object a message
trash can constructor – can create itself commands – add trash, empty yourself query – Lid open or closed? How much trash?
properties attributes – things that describe an object components – things that are “part” of an object association – things an object knows about
object state set of all object properties
objects in java properties – variables capabilities - functions
Car properties: make, model, year, color capabilities: turn on, accelerate, brake, roll windows
Class “Instances” of Class
class Car { String make; String model; int year; String color; void Car() { … } void turnOn() { … } void accelerate() { … } void decelerate() { … } void rollWindows() { … } }
class hello{ void main(String[] args) { … } }
variables <type> <name> = <value>
creating objects <class_name> <name> = new <class_name>() Car prius = new Car();
class CarTest { void main(String[] args) { Car myMustang = new Car(); myMustang.make = “Ford”; myMustang.model = “Mustang”; myMustang.year = 1969 myMustang.color = “brown”; myMustang.turnOn(); myMustang.accelerate(); } }
class CarTest { void main(String[] args) { Car myMustang = new Car(“Ford”, “Mustang”, 1969, “black”); myMustang.turnOn(); myMustang.accelerate(); } }
interface LightBulb bulb = new LightBulb();
interface LightBulb bulb = new LightBulb(); bulb.turnOn();