Chapter 10 Thinking in Objects

Slides:



Advertisements
Similar presentations
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Advertisements

Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 9 Objects and Classes.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 7 Object-Oriented Programming.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 10 Thinking in Objects.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Introduction to Object-oriented programming and software development Lecture 1.
Object Oriented Design: Identifying Objects
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
1 Chapter 10 Object-Oriented Thinking. 2 Class Abstraction and Encapsulation Class abstraction means to separate class implementation details from the.
CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.
Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design Guidelines.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Chapter 5 Programming with Objects and Classes OO Programming Concepts OO Programming Concepts Declaring and Creating Objects Declaring and Creating Objects.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Object-Oriented Design.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
OOP Basics Classes & Methods (c) IDMS/SQL News
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
COP 4331 – OOD&P Lecture 7 Object Concepts. What is an Object Programming language definition: An instance of a class Design perspective is different.
Chapter 11: Abstract Data Types Lecture # 17. Chapter 11 Topics The Concept of Abstraction Advantages of Abstract Data Types Design Issues for Abstract.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Chapter 10 Thinking in Objects
Topic: Classes and Objects
Object Oriented Programming
Chapter 7 Object-Oriented Programming
Chapter 10 Thinking in Objects
Chapter 8: More About OOP and GUIs
Reference: COS240 Syllabus
Chapter 10 Thinking in Objects
The Object-Oriented Thought Process Chapter 1
Chapter 11 Object-Oriented Design
Reference: COS240 Syllabus
Chapter 10 Thinking in Objects
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
ATS Application Programming: Java Programming
Chapter 13 Abstract Classes and Interfaces
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
Chapter 10 Thinking in Objects
UML Class Diagrams: Basic Concepts
Object Oriented Analysis and Design
Chapter 9 Thinking in Objects
Chapter 3 Introduction to Classes, Objects Methods and Strings
Defining Your Own Classes Part 1
Unit-2 Objects and Classes
Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach
Software Engineering Lecture #11.
Chapter 9 Objects and Classes
ISC321 Database Systems I Chapter 10: Object and Object-Relational Databases: Concepts, Models, Languages, and Standards Spring 2015 Dr. Abdullah Almutairi.
Chapter 20 Object-Oriented Analysis and Design
Chapter 9 Thinking in Objects
Introduction to Data Structure
Basic OOP Concepts and Terms
Object Oriented Programming in java
Java Programming Language
Defining Classes and Methods
CMSC202 Computer Science II for Majors Lecture 10 and 11 – Inheritance
Object-Oriented PHP (1)
Chapter 10 Thinking in Objects Part 1
2.1 Introduction to Object-Oriented Programming
Chapter 10 Thinking in Objects
Presentation transcript:

Chapter 10 Thinking in Objects Dr. Clincy

Structured or Procedural Programming Versus OO Programming Structured Programming Languages Fortran Pascal Ada C BASIC Description: Procedural approach tackles a specific problem upfront – build exactly what is needed to solve the problem, focus on using the specific data needed and in designing and implementing the needed subroutines and functions (or “methods” in using an OOP term) – focuses on specific data and methods. Object-Oriented Programming Languages Java Python Ruby C# C++ Visual Basic Description (Student): The initial step is to design and build classes and their operations (i.e. methods) with no real focus on a specific problem. The second step is to use the derived objects and their methods and data to solve some specific problem. In addition to a focus on data and methods in general, also focuses on “Classes and Objects” Description (Professional): The 1st step is to look for existing classes and objects that can be used to solve some specific problem. If no luck, determine which existing classes and objects can be altered. If no luck, build new classes and objects. Dr. Clincy

Structured or Procedural Programming Versus OO Programming Focuses on designing methods Data and operations on the data are separated Data must be passed to the methods Programs are more abstract and catered for a specific problem/use/etc.. Code reuse is not suitable Involves thinking in terms of specific methods and data Object-Oriented Programming Couples data and methods into objects Programs mirror real world Languages are built to easy allow objects to have associated attributes and activities Code reuse is suitable Involves thinking in terms of objects (and classes) Btw: encompasses structured programming with an added dimension that integrates data with operation into objects Dr. Clincy

Class Abstraction and Encapsulation Class abstraction means to separate class implementation from the use of the class. The creator of the class provides a description of the class and let the user know how the class can be used. The user of the class does not need to know how the class is implemented. The detail of implementation is encapsulated and hidden from the user. A description and collection of public constructors, methods, and field that are accessible from outside the class is called the Class’s Contract Encapsulation For OOP, it is really all about understanding Class’s Contract in not re-inventing the wheel Explain OOL to high-level language to low-level language concept Dr. Clincy

Example: Building a Car from a OOP Perspective Car has many components such as carburetor, starter, alternator, engine, AC system, gas tank, transmission system, etc Each component can be viewed as an object that has properties and methods To get the components to work together, you only need to know how the component is used and how it interacts with one another (abstraction) – OOP way of Thinking You don’t need to know how each component works internally – you can build the car without knowing (encapsulation). Dr. Clincy

Class Relationships In designing classes, you must first explore the relationships among classes. COMMON CLASS RELATIONSHIPS Association – a general binary relationship that describes an activity between two classes Aggregation – an association that represents an ownership relationship between two objects Composition – an association that represents an “exclusive” ownership relationship between two objects Inheritance – the ability to generate a specialized class (subclass) from a general class (superclass). Will cover this in a later chapter. Dr. Clincy

Association – UML Example Association – a general binary relationship that describes an activity between two classes A Faculty member teaching a course is an association between the Faculty Class and the Course Class A Student taking a Course is an association between the Student Class and the Course Class Relationship’s “label” and the relationship’s direction Relationship’s “label” and the relationship’s direction Student Role name that describes role in relationship A course is taught by only one faculty member A course may have 5 to 60 students A student may take any number of courses A faculty may at most 3 courses Dr. Clincy

Association – Implementation The association relations are implemented using data field and methods in classes. The Faculty-Teaches-A-Course relationship is implemented using addCourse method in Faculty class and setFaculty method in the Course class The Student-Taking-A-Course relationship is implemented using addCourse method in Student class and addStudent method in the Course class The Faculty class can use a list to store the courses the faculty is teaching The Student class can store a list of courses the student is taking The Course class can use a list to store the students taking the course The Course class can use a data field to store the faculty who teaches the course Dr. Clincy

Aggregation and Composition Aggregation – an association that represents an ownership relationship between two objects Owner object is called the “aggregating object” and it’s class is called the “aggregating class” Subject object is called the “aggregated object” and it’s class is called the “aggregated class” Name Student Address If the subject object CAN NOT exist without the Owner object, this aggregation is called “Composition” Name cannot exist without Student Address CAN exist without Student Up to 3 students can share the same address Dr. Clincy

Aggregation and Composition - Implementation The Student-Has-A-Name relationship is implemented using the data field “name” in the Student class – the aggregating class The Student-Has-An-Address relationship is implemented using the data field “name” in the Student class – the aggregating class NOTE: Since aggregation and composition relationships are represented using classes in similar ways, many textbooks don’t differentiate them and call both compositions. Dr. Clincy

Aggregation Between Same Class Aggregation may exist between objects of the same class. For example, a person may have a supervisor. public class Person { // The type for the data is the class itself private Person supervisor; ... } The Person-Has-A-Supervisor relationship implementation What happens if a person has several supervisors? Can use an array to implement the Person-Has-Many-Supervisors relationship Dr. Clincy

Wrapper Classes Boolean Integer Character Long Short Float Byte Double Primitive data types (ie. Bool, Char, Int, Byte, etc) are NOT treated like objects – for performance and efficiency reasons However, many Java methods require the use of objects as arguments Java provides the ability to incorporate or “wrap” a primitive data type value into an object – wrapper class Java provides the following wrapper classes via it’s java.lang package: Boolean Character Short Byte Integer Long Float Double NOTE: (1) The wrapper classes do not have no-arg constructors. (2) The instances of all wrapper classes are immutable, i.e., their internal values cannot be changed once the objects are created. Dr. Clincy

We will cover the String class in the next lecture. Let’s review and start Lab 2 Dr. Clincy