CMSC 202 Fall 2010, Advanced Section Designing with Objects.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Introduction to Object Orientation System Analysis and Design
Classes and Objects CMSC 202. Version 9/122 Programming & Abstraction All programming languages provide some form of abstraction. – Also called information.
1 OBJECT-ORIENTED CONCEPTS. 2 What is an object?  An object is a software entity that mirrors the real world in some way.  A software object in OOP.
Solutions to Review Questions. 4.1 Define object, class and instance. The UML Glossary gives these definitions: Object: an instance of a class. Class:
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented Analysis and Design
Chapter 1 Object-Oriented System Development
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
Object Oriented System Development with VB .NET
1 Basic Object Oriented Concepts Overview l What is Object-Orientation about? l What is an Object? l What is a Class? l Constructing Objects from Classes.
HST 952 Computing for Biomedical Scientists Lecture 2.
Chapter Chapter 1 Introduction to Object-Oriented Programming and Software Development.
Object-oriented Programming Concepts
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Introduction to Object-oriented Programming Introduction to Object-oriented Programming CMPS 2143.
CMSC 202 Computer Science II for Majors Fall 2009 Introduction.
BACS 287 Basics of Object-Oriented Programming 1.
Programming Languages and Paradigms Object-Oriented Programming.
Introduction to Object-oriented programming and software development Lecture 1.
O BJECT O RIENTATION F UNDAMENTALS Prepared by: Gunjan Chhabra.
OBJECT AND CLASES: THE BASIC CONCEPTS Pertemuan 8 Matakuliah: Konsep object-oriented Tahun: 2009.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
© 2005 course technology1 1 University Of Palestine UML for The IT Business Analyst A practical guide to Object Oriented Requirement Gathering Hoard Podeswa.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Stephenson College DP 96 1 Object-Orientation by Derek Peacock.
Object Oriented Programming Principles Lecturer: Kalamullah Ramli Electrical Engineering Dept. University of Indonesia Session-3.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
OOP Class Lawrence D’Antonio Lecture 3 An Overview of C++
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section on UML: look at class diagrams but.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Learners Support Publications Object Oriented Programming.
CSC 131 Fall 2006 Lecture # 6 Object-Oriented Concepts.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (1/2)
CMSC 202 Classes and Objects: The Basics. Version 9/09 2 Programming & Abstraction All programming languages provide some form of abstraction. –Also called.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Salman Marvasti Sharif University of Technology Winter 2015.
Object-Oriented Programming Chapter Chapter
ADT data abstraction. Abstraction  representation of concepts by their relevant features only  programming has two major categories of abstraction process.
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
ISBN Object-Oriented Programming Chapter Chapter
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Lesson 1 1 LESSON 1 l Background information l Introduction to Java Introduction and a Taste of Java.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
CMSC 202 Classes and Objects. Aug 6, Programming Languages All programming languages provide some form of abstraction Procedural language (eg C)
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (1/2)
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ISBN Chapter 12 Support for Object-Oriented Programming.
CMSC 202 Computer Science II for Majors Fall 2010 Introduction Version 9/101.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
Classes and Objects: Encapsulation
Classes and OOP.
Object Oriented Concepts -I
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Chapter 10 Thinking in Objects
Advanced Programming Behnam Hatami Fall 2017.
Object-Oriented PHP (1)
Handout-2(a) Basic Object Oriented Concepts
Presentation transcript:

CMSC 202 Fall 2010, Advanced Section Designing with Objects

Programming & Abstraction All programming languages provide some form of abstraction. –Also called information hiding –Separating how one uses a program module from its implementation details Procedural languages: –Data abstraction: using data types –Control abstraction: using functions Object-oriented languages: –Data and control abstraction: using classes Our world is object-oriented. Version 9/102

3 Procedural vs. OO Programming Examples: C, Pascal, Basic, Python Modular units: functions Program structure: hierarchical Data and operations are not bound to each other. Examples: Java, C++, Ruby Modular units: objects Program structure: a graph Data and operations are bound to each other. ProceduralObject-Oriented (OO) A Hierarchy of Functions A Collection of Objects

Encapsulation We will use the term encapsulation in two different ways in this class (and in the text) Definition #1: "Inclusion" (“bundling"): bundling of structure and function Definition #2: “Exclusion” (“access control”) Strict, explicit control of how our objects can be used Version 9/104

Procedural vs OO: Example Procedural: if (shape.type == SQUARE) area = shape.width ** 2; else if (shape.type == TRIANGLE) area = (shape.width * shape.height) / 2; else if (shape.type == CIRCLE) area = ((shape.width / 2) ** 2) * PI; OO: shape.getArea(); Version 9/105

Objects are Models Model Type I: Objects as Models of the Real World Programming “objects” are accurate representations of physical entities Goal is realism We want to create representations of “things”, with: Observable attributes Physical functionality E.g.: Physical vending machine: A given bin has physical capacity limit float binDepth, spiralTurnSize; Version 9/106

Objects are Models Model Type II: Objects as Models of Conceptual Entities We think programmatically from the outset Goal is to simplify programming E.g.: generic vending machine slot representation A bin is an unbounded array (a pysical vending machine cannot recalibrate once built) Might also want to track “numItemsVended”, e.g., to find popular positions. Not restricted to what is a “physical attribute” Version 9/107

Objects are Models Should we use physical or abstract model? Humans are better at relating to physical Computers can take advantage of abstract General rule: start with concrete, then start abstracting, extending Don’t be dogmatic! Version 9/108

What Parts to Model: Depends on purpose of model Can not (and should not) model everything Can try to anticipate likely future needs, though Running Theme #1 (RT1): “Multiply-by-PI Rule” E.g.: Bank Account Account type Account number Name Address Balance Version 9/109

What Parts to Model:... But what about: Transaction history Number of overdrafts Interest rate This might be function of account type (stored in bank-wide object) …Or, might also want to be able to set individually per-account Also, might want to extract personal info (name, address, etc.) into separate object Version 9/1010

What Parts to Model: What about methods? Again, same considerations of: Physical vs. abstract models Designing for future needs Version 9/1011

Order of Design Tasks In general, do data layout first I.e., consider “complete” set of attributes you want to model; aka: aka: instance variables state variables Properties Then do top-level design of functionality needed (methods) Easier once you have attributes in mind Version 9/1012

Related Concepts Composition A mechanism for incorporating other, existing objects as components of our new object Inheritance A way to incrementally build on the design of existing objects to create related, more complex objects Version 9/1013

Version 9/0914 What’s a Class? From the dictionary A kind or category A set, collection, group, or configuration containing members regarded as having certain attributes or traits in common. From OOP (Rumbaugh, et al) A group of objects with similar properties, common behavior, common relationships with other objects, and common semantics. We use classes for abstraction purposes.

Version 9/0915 Classes All objects are unique. Objects that are identical except for their state can be grouped into a class. Class of cars Class of birds Class of playing cards Class of bakers

Version 9/0916 A Class is a Model A class is a model for a group of objects. The focus of the class is the common behavior of the objects the class models. A class’ behavior may also referred to as a service, operation, action, or command. The model also contains common attributes of the objects. The attributes exist to support the model’s behaviors.

Version 9/1017 Objects, Classes If a class is: A data type defining a template for a set of: Attributes - make up the object’s “state” Operations - define the object’s “behaviors” deposit money withdraw money check balance transfer money more? Bank Account account number owner’s name balance interest rate more? String sequence of characters more? compute length concatenate test for equality more? operations (behaviors) name attributes (state)

Version 9/1018 Objects, Classes …Then an object is a particular “instance” of a class. Bergeron’s AccountFrey’s AccountMitchell’s Account Susan Mitchell $ % For any of these accounts, one can deposit money withdraw money check the balance transfer money Ryan Bergeron $1, % Dennis Frey $ %

Version 9/0919 Class Examples What services/behaviors might be appropriate for the following things? A red-green-yellow traffic light A garage door opener A bank account

Version 9/0920 A Class is a Type An Object is a Variable Variables of the class type (objects) may be created just like variables of built-in types. All bakeries have similar (class) properties. You can create as many objects of the class type as you like. There is more than one baker in Baltimore. OOP challenge is to define the classes and create the objects that match the problem. Do we need a farmer class?

Version 9/0921 Object Interface The requests you can make so an object will do something are determined by its interface. The interface is determined by its class type. IMPORTANT Do you need to know how a bakery works to get bread? Who needs to know how a bakery works? Bakery makeBagel() makeBread() sellBagel() sellBread() TYPE INTERFACE

Version 9/0922 Implementation Code and hidden data in the object that satisfies requests comprise the implementation. What’s hidden in a bakery? Each request in the interface has an associated method. When a particular request is made, that method is called. In OO-speak we say that you are sending a message to the object, which responds to the message by executing the appropriate code.