Basic Object-Oriented Concepts 22-Apr-17
Object Oriented Programming Object-oriented programming (OOP) is a programming language model organized around objects Objects have a state or properties (information about the object stored in variables) size, height, position, balance Objects have a behavior or actions that it performs. Methods. move ____ turn____ Programming languages have predefined methods for each class.
Class <CAR> creates cars Everything in Java is in a class. Class called Car The class creates objects The class represents a template for creating objects of that class.
Class Car creates car objects: Share same attributes but they store different values. <7_series_BMW> Object <VW_Beetle> Object <Ford_Mustang> Share same attritubes: They have a ……. color – model# name doors You would store this in variables because it would be different for each object.
Example: A “Rabbit” object You could (in a game, for example) create an object representing a rabbit It would have data which is stored in variables. How hungry it is? = hungry = true; How frightened it is? frightened = false; Where it is? location = 0; What is its name? name = “Rabbit”; And methods: things it can do eat, hide, run, dig
Class <CAR> startEngine checkEngine fillTank getAmountOfGas Method of a Class Class <CAR> Every class has predefined methods for the object created. Methods allow the object created to perform an action startEngine checkEngine fillTank getAmountOfGas
Control flow of a program Three types of control flow that are used to execute a program Sequentially - all code will run sequentially Conditionals (if statements) Loops (repeats)
Introduction to programming thru SNAP Cloud storage if you create user name The program interface Click on object and script area to build your code