Slide 1

Slide 1 text

Object Oriented Programming Class Ten: February 6, 2014

Slide 2

Slide 2 text

Procedural Programming Review Design Method = Top Down Start with a problem (procedure) and then systematically break the problem down into sub problems (sub procedures). Procedures, also known as routines, subroutines, methods, or functions simply contain a series of computational steps to be carried out. Issues?

Slide 3

Slide 3 text

SegSim Explanation “Segregation Simulation”: A simple model for investigating how over time communities can become segregated based on various prejudices. 1. Break the problem down into one dimension; a street initially populated with equal probability either black ‘B’, white ‘W’ or empty ‘ ‘ houses. 2. We then allow the system to evolve by randomly selecting houses and applying a simple condition: If the house is surrounded on both sides by a house different to itself, it will decide to move to an empty location in the street where this condition is not satisfied. In the unlikely event that a suitable location cannot be found after a designated number of attempts, the house will leave the street.

Slide 4

Slide 4 text

SegSim Sample Output | BW W BWB BWBBWWBWWW W B BW BW WW BWW BWWW | : 17   | BW W BWB BWBBWWBWWW WBB BW BW WW WW BWWW | : 15   | BW W BWB BWBBWWBWWW WBB B BWWWW WW BWWW | : 13   | BBW W BWB BWBBWWBWWW WBB B WWWW WW BWWW | : 11   | BBW W BWBBBWBBWWBWWW WBB B WWWW WW WWW | : 8   | BBW BWBBBWBBWWBWWWWWBB B WWWW WW WWW | : 6   | BBW BWBBB BBWWBWWWWWBB B WWWW WW WWWW | : 5   | BBW WBBB BBWWBWWWWWBB BB WWWW WW WWWW | : 3   | BBWW BBB BBWWBWWWWWBB BB WWWW WW WWWW | : 1   | BBWW BBBB BBWW WWWWWBB BB WWWW WW WWWW | : 0

Slide 5

Slide 5 text

SegSim Modified Rules Suppose we want to add a different type of house that plays by different rules, then see how the simulation differs? Consider a nomad type house (label ‘N’) which does not care about its neighbors. However, it remembers how long it has been in one location, and if longer than a specified threshold it moves to a new location. How must we modify the original program in order to account for these new rules?

Slide 6

Slide 6 text

Object Oriented Programming An object oriented program may be viewed as a collection of interacting objects, as opposed to the procedural model, in which a program is seen as a list of functions to perform. The aim of object-oriented programming is to try to increase the flexibility and maintainability of programs. Data before action.

Slide 7

Slide 7 text

Object Oriented Programming A programming paradigm that represents concepts as objects that have data fields (properties that describe the object) and associated procedures known as methods. Objects, which are instances of classes, are used to interact with one another to design applications and computer programs. Some verbiage can vary.

Slide 8

Slide 8 text

What is a class? A collection of objects that have common properties, operations and behaviors. A combination of state (properties) and behavior (methods). A data type, and objects are instances of that data type. In other words, classes are prototypes from which objects are created. The blueprint.

Slide 9

Slide 9 text

What is an object? An instance of a class. An object receives all of the characteristics of a class, including all of its default data and any actions that can be performed by its methods. Objects can communicate. An object passes a message to another object, which results in the invocation of a method. The “object” you build from the blueprint.

Slide 10

Slide 10 text

What is a method? A set of functions contained within a class. Allows you to do “stuff.” The response to a message is executing a method. Sending a message means calling a method.

Slide 11

Slide 11 text

What is a property? A default set of data stored in a class. A class can have multiple properties and the properties can be changed dynamically through the methods of the class.

Slide 12

Slide 12 text

What is encapsulation? Preventing access to data by any means other than those specified.

Slide 13

Slide 13 text

What is inheritance? Multiple classes may share some of the same characteristics, and have things in common with one another, but also may have certain properties that make them different. Object oriented programming allows classes to inherit commonly used state and behavior from other classes.

Slide 14

Slide 14 text

What is inheritance?

Slide 15

Slide 15 text

Major Distinction Procedural • Uses procedures to operate on data structures* Object-Oriented • Bundles the two together, so an object, which is an instance of a class, operates on its "own" data structure. * A particular way of storing and organizing data in a computer so that it can be used efficiently