Object-Oriented Concepts

Slides:



Advertisements
Similar presentations
Object-Oriented Programming Session 9 Course : T Programming Language Concept Year : February 2011.
Advertisements

Advanced Piloting Cruise Plot.
1 Classes and Objects in Java Basics of Classes in Java.
Final and Abstract Classes
1 Inheritance Classes and Subclasses Or Extending a Class.
Copyright © 2002 Pearson Education, Inc. Slide 1.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Learning Objectives Structures Structure types Structures.
Copyright © 2003 Pearson Education, Inc. Slide 1.
Chapter 1 The Study of Body Function Image PowerPoint
Writing Pseudocode And Making a Flow Chart A Number Guessing Game
10 Copyright © 2005, Oracle. All rights reserved. Reusing Code with Inheritance and Polymorphism.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
My Alphabet Book abcdefghijklm nopqrstuvwxyz.
Year 6 mental test 5 second questions
Part 1 Marketing Dynamics
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 10 Arrays and Tile Mapping Starting Out with Games & Graphics.
Configuration management
Object-Oriented Software Engineering Visual OO Analysis and Design
What Is Cost Control? 1 Controlling Foodservice Costs OH 1-1.
ABC Technology Project
Object Oriented Programming with Java
By Waqas Over the many years the people have studied software-development approaches to figure out which approaches are quickest, cheapest, most.
24-Aug-14 Abstract Classes and Interfaces. Java is “safer” than Python Python is very dynamic—classes and methods can be added, modified, and deleted.
Problem Solving and Algorithm Design
Lets play bingo!!. Calculate: MEAN Calculate: MEDIAN
OBJECT-ORIENTEDNESS. What is Object-Orientedness? model system as a collection of interacting objects O-O Modelling  O-O Programming ► similar conceptual.
GG Consulting, LLC I-SUITE. Source: TEA SHARS Frequently asked questions 2.
Addition 1’s to 20.
25 seconds left…...
Structures. Procedural (Imperative) Languages Procedural languages work on the basis of explicitly telling the computer ‘how to do something’; by using.
1 Object Oriented Programming Ras Bodik, Thibaud Hottelier, James Ide UC Berkeley CS164: Introduction to Programming Languages and Compilers Fall 2010.
H to shape fully developed personality to shape fully developed personality for successful application in life for successful.
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 15 Programming and Languages: Telling the Computer What to Do.
Week 1.
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Chapter 11 Component-Level Design
Chapter 13 – Introduction to Classes
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 14: Protection.
Abstract Class, Packages and interface from Chapter 9
1 Abstract Class and Packages from Chapter 9 Lecture.
Modeling Main issues: What do we want to build How do we write this down.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Object Oriented System Development with VB .NET
Principles of Object-oriented Programming Programming Language Paradigms August 26, 2002.
Object-oriented Programming Concepts
C++ fundamentals.
Introduction To System Analysis and design
Object Oriented Software Development
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
11 1 Object oriented DB (not in book) Database Systems: Design, Implementation, & Management, 6 th Edition, Rob & Coronel Learning objectives: What.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
Understanding Objects and Classes
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 1 Introduction to Object-Oriented Development.
Next Back MAP MAP F-1 Management Information Systems for the Information Age Second Canadian Edition Copyright 2004 The McGraw-Hill Companies, Inc. All.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Design
JAVA By Waqas.
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
Workshop for Programming And Systems Management Teachers
Presentation transcript:

Object-Oriented Concepts Intro-OO

What is Object-Oriented? This means that we focus on the objects not just the procedures Focus on who (what objects?) as well as what (what do the objects do?) This contrasts with procedural programming in which we focus on the task that needs to be done. You may break that task up into smaller parts. In object-oriented programming we need to know who (what class) as well as what (procedures). Object-oriented programming is concerned with responsibility. Who (what object) is responsible for doing the job, not just what jobs need to be done. Intro-OO

Example Imagine that you are put into a group to do a job: say design and sell t-shirts to raise money for an organization You would want to specify the tasks to be done You would also want to specify who will work on each task Talk about why it is important to say who will do each task? How do you decide who will do the task? Why is it important to know what needs to be done? Is it a good idea to assign all the tasks to one person? Is it a good idea to assign tasks based on skills people have? Intro-OO

Task List Design T-Shirts Make the T-Shirts Sell T-Shirts What will people buy? What will look good? What would be too expensive? Make the T-Shirts Where to get them? How to add the design? How long will they take to make? Sell T-Shirts How much to sell them for? When and where to sell? How do you keep track of who sold what and who ordered what? Each task may have one or more sub-tasks. You might assign a person to each sub-task. Intro-OO

Job List Designers Manufacturers Sellers Responsible for designing the t-shirts Manufacturers Responsible for making the t- shirts Sellers Responsible for selling the t- shirts This is one way to organize who will do the work and what to call each category (class). You would probably have 1 or more designers, several manufacturers, and many sellers. Intro-OO

Objects have Responsibilities An object-oriented design Determines the tasks to be done Determines what objects will be responsible for each task No one object does everything Objects work together to accomplish tasks The assignment of responsibilities is the key skill in object- oriented design Intro-OO

What is an Object? A person, place, or thing That knows something about itself Has data (attributes, fields) A cashier has a id, name, and a password And can do something Has operations (methods) A cashier can total the items, take payment, make change Point out objects in the room (like a book, pen, computer, person, etc). Talk about what type of object it is, what data it has, what it can do. Go through your example real-world scenarios. Point out the objects, their types, data, and operations. The picture is a cashier in a music store. The data is his name and password. The operations are how to “ring up” and “take payment”, and “make change”. Intro-OO

What is a Class? The type of an object The way we classify an object “The Idiot” by Dostoevsky is a book “War and Peace” by Tolstoy is a book Mary is a cashier Tasha is a cashier Grouping of objects with the same data and operations Objects are instances of a class. This slides shows two book objects of the class book. Intro-OO

Class: Example Mary is a cashier Tasha is a cashier Cashier is a class All cashiers have an id, name and password Each will have a different id, name, and password All cashiers can total an order, take payment, make change Intro-OO

Object Data Each object has its own data Tasha’s id is 4 and password is mhall Mary’s id is 3 and password is smile4 All cashier objects have an id, name, and password Changing Mary’s data won’t affect Tasha’s data Object data is also called instance variables, object variables, and object fields. Intro-OO

Teaching Objects and Classes Point out various objects in the room and ask what “type” of thing are they. Ask what data is known about each type and what operations can objects of that type do. Point out that there are several objects of the same “type”. How are they the same and how different? There are probably computers in your room. What do we mean by a “computer”? What data does it have (manufacturer, size screen, size memory, etc). What can it do? Point out that nobody had to tell the students that these where computers. How did they know? They fit their idea of what a computer looks like. Intro-OO

Find Object Types Exercise List the “types” of objects in this picture Intro-OO

History of Objects and Classes Plato’s Republic (~375 BC) theory of forms Let us take any common instance; there are beds and tables in the world -- plenty of them, are there not? Yes. But there are only two ideas or forms of them -- one the idea of a bed, the other of a table. Plato’s Republic is online at http://plato.evansville.edu/texts/jowett/republic39.htm Each bed is an object (instance) of the bed class. Intro-OO

History of Inheritance Aristotle Parts of Animals (350 BC) describes inheritance. Linnaeus’s Species Plantarum (1753) applied inheritance systematically and is the basis for modern botanical nomenclature. Mammal Aristotle’s Parts of Animals is online at http://www.knuten.liu.se/~bjoch509/works/aristotle/parts_animals.txt. Information on Carl Linnaeus - Carl von Linné can be found online at http://www.systbot.uu.se/dept/history/linneaus.html. Cat Dog Intro-OO

C++ Developed by Bjarne Stroustrup at Bell Labs in 1985 created a highly-efficient version of Simula by extending the C language very popular in the late 80s to 90s still popular for 3d graphics Bjarne Stroustrup. The Design and Evolution of C++. Reading, MA: Addison-Wesley, 1994. Bjarne Stroustrup, “A History of C++”. History of Programming Languages (HOPL-II). J. E. Sammet. New York, ACM: 699-769, 1993. Bjarne Stroustrup’s home page is at http://www.research.att.com/~bs/. Intro-OO

Java In 1991, Sun Microsystems began an internal project to produce a language that could run on intelligent consumer electronic devices James Gosling created the programming language Oak for this project as a highly portable, object-oriented programming language. Oak evolved into Java and was released in 1995. Very popular James Gosling’s home page is at http://java.sun.com/people/jag/. Intro-OO

Simulation Object-oriented development means creating a simulation of the problem We need to know the objects in the problem So we can create software objects to represent them We need to know the types of the objects (classes) So we can define the data and the operations for all objects of that type We can’t put the “real” objects into the computer so we need to make software objects that represent the “real” objects. Intro-OO

Classes Create Objects The class can be thought of as a recipe, blueprint, or factory Many objects can be created from one class Objects keep track of the class that created them I am an object (instance) of the Cookie class When you create an object it has a reference to the object that represent the class that created it. So, objects always know what type (class) they are. Intro-OO

Classes Define the Objects The computer doesn’t know what we mean by a car or cashier We define the class Cashier so that the computer will understand what a cashier or bank account “is” and what it can “do” In the context of the problem we are trying to solve Then the computer can create objects from the classes Intro-OO

Abstraction Pull out only the important details about the thing we are simulating Cashiers have hobbies but we don’t need to know about them Intro-OO

What do Objects Look Like? Mary : Cashier Tasha : Cashier Objects are created with space for their data (Instantiated) Object have a reference to the object that represents the class Object of the class “Class” id = 3, name=“Mary” password = smile4 id = 4 Name=“Tasha” password = mhall Cashier : Class Name = Cashier Methods = totalOrder() takePayment(payment) makeChange() To get the class object that represents the class use object.getClass(); To check if an object is an instance of a class use instanceof(className); There is actually an array of Method objects that holds the methods for a class. There is also an array of Field objects which describes the fields in the class. Intro-OO

Software Objects are Models The objects we create in software are models of the physical object We can’t stick a person in our software We can create a model of the person with the information we need to know for that person for our task Cashier id name password Intro-OO

Communicating Objects Objects in the simulation need to communicate They send each other messages Messages cause methods (operations) to be executed Methods are written with parameters to represent variable data determined by the caller Methods are passed arguments when they are called later Clean your room, please If I get a message from someone asking me to do something I can choose to do the action or not. Intro-OO

Data Responsibility Objects are responsible for their data The data should not be allowed to get into an invalid state Like withdrawing more money than is in a back account Intro-OO

Encapsulation Data and operations are combined in classes All changes to data should be done by methods in the class Making sure that the data stays valid Data should be private data data If an object in class A wants to change the data in an object of class B it needs to ask the object of class B to do the change (by sending a message). The object of class B can refuse to do the change. methods methods message Intro-OO

Why use Encapsulation? If something goes wrong we know where the trouble is Some class didn’t protect the data or didn’t make sure the data was valid If something changes it is easy to find the class to fix If I need to add or change data the methods that work on it are together in the class If you need a method it is easy to check if such a method exists In procedural or functional programming you create functions or procedures that act on data and any function or procedure can act on any data. So, when data is in an invalid state you don’t know which procedure or function caused the problem. You have to check all the code that is passed the data to find where the problem occurred. In large procedural or functional projects it is easy for people to create several functions that do the same or similar things because they aren’t aware of the others. Intro-OO

Data Hiding In OO Programming we hide data from objects in other classes No direct changing of data in objects of another class Objects send messages asking for operations to be done on the data They don’t need to know how an object is going to do something as long as they do it We can also think of this as security. An object keeps its data secure and doesn’t let objects of other classes mess with the data. A customer object could ask a bank account object to withdraw more money than is in the bank account but the bank account object won’t let it. The customer object doesn’t even need to know how the bank account object stores the current balance. The customer object can’t directly change the current balance. Intro-OO

Inheritance Did you get features or abilities from your parents? People inherit physical characteristics Some people inherit abilities: music Inheritance in OO means receiving data and methods from your parent In Java you can only have one parent Intro-OO

Inheritance in our Models One class can inherit from another Gets all the fields and methods The class you inherit from is called Parent, superclass, base class The class doing the inheriting is called Child, subclass, derived class Person Parent Student Child This type of diagramming is called UML which is the Unified Modeling Language and is a standard way to show object-oriented designs. Intro-OO

Teaching Inheritance Point out inheritance in common objects What is a book? What is a dictionary? Talk about the things that are the same Talk about the things that are different Some other ideas are (teacher, math teacher), (school, elementary school, middle school, high school) Intro-OO

Polymorphism Literally: many forms In Object-Oriented development it means that what happens when a message is sent to an object depends on the type (class) of the object at runtime Intro-OO

How Does Polymorphism Work? If a class is declared to be final then the compiler can figure out the location of a method that matches the message If a class can be subclassed then a variable declared to be of the parent type can point to an object of the parent class or any subclass at run-time the compiler can’t determine the method to invoke the method to invoke is figured out at run-time Intro-OO

The End!! Intro-OO