1 21 COP 3540 Data Structures with OOP Overview: Chapter 1.

Slides:



Advertisements
Similar presentations
Data Structures.
Advertisements

Overview of Data Structures and Algorithms
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
1 l Inheritance Basics l Programming with Inheritance l Dynamic Binding and Polymorphism Inheritance.
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
Chapter 8 Inheritance Part 2. © 2004 Pearson Addison-Wesley. All rights reserved8-2 Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
Inheritance Polymorphism Briana B. Morrison CSE 1302C Spring 2010.
Chapter 3 – Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To.
ACM/JETT Workshop - August 4-5, :Inheritance and Interfaces.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Object-Oriented PHP (1)
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 3 Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To understand.
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
Chapter 13: Object-Oriented Programming
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
C o n f i d e n t i a l Developed By Nitendra NextHome Subject Name: Data Structure Using C Title: Overview of Data Structure.
1.A file is organized logically as a sequence of records. 2. These records are mapped onto disk blocks. 3. Files are provided as a basic construct in operating.
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to Classes and Objects Outline Introduction Classes, Objects, Member Functions and Data.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSC 212 Object-Oriented Programming and Java Part 1.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
1 21 COP 3540 Data Structures with OOP Overview: Chapter 1.
Inheritance Extending Class Functionality. Polymorphism Review Earlier in the course, we examined the topic of polymorphism. Many times in coding, we.
Inheritance in the Java programming language J. W. Rider.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Topic 4 Inheritance.
Programming in Java CSCI-2220 Object Oriented Programming.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Object-Oriented Programming Chapter Chapter
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Classes, Interfaces and Packages
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Chapter 3 Implementing Classes
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
ISBN Chapter 12 Support for Object-Oriented Programming.
Object-Oriented Programming: Classes and Objects
Chapter Three - Implementing Classes
Inheritance Basics Programming with Inheritance
Computer Programming with JAVA
Support for Object-Oriented Programming
Introduction to Data Structure
Introduction to Object-Oriented Programming
Lecture 10 Concepts of Programming Languages
C++ Object Oriented 1.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

1 21 COP 3540 Data Structures with OOP Overview: Chapter 1

2 21 Important Notice  I will cover several slides (but not all) in these sets of slides. I will outline those that need elaboration.  You are responsible for studying and knowing all the slide materials and the text materials.  Exams and short quizzes will be taken largely from these slides and topics brought up in class.

3 21 Why Data Structures and Algorithms?  Data Structures are merely different arrangements of data in primary memory or on disk, and  Algorithms are sequences of instructions that manipulate the data in these data structures in a variety of ways.

4 21 Examples of Some Data Structures  Many data structures:  Arrays  Linked lists  Stacks  Binary Trees  Red Black Trees  Trees  Hash Tables  Heaps, etc.  Different algorithms are needed to build, search, and manipulate data stored in these various structures

5 21 Plain Facts:  The plain fact is that many items in nature have an ‘natural arrangement’ with their predecessor or successor element.  Think: records in a sequential file  Think: a family ‘tree’  If  we model this natural occurring arrangement in the computer using some kind of data structure that reflects the real world realities of the data and their implicit relationships,  then  we need specialized algorithms for building, retrieving, and otherwise accessing the data itself.

6 21 Examples of ‘Plain Facts’ Example 1  Consider a sequence of numbers  may be best represented in an array.  We need to ‘search’ the array for a number.  An Algorithm processes this arrangement of data.  If ordered and sufficiently large: binary search  If unordered: sequential search is our only option. (Performance issues can be huge: either way.)

7 21 Examples of ‘Plain Facts’ Example 2  We may best ‘represent’ (model) a family and children by a tree structure. (a logical data structure)  How do we add members to such a tree?  How do we Search?  How to delete when there are ‘descendents’  How do we best Add to a large tree?  We need very specific Algorithms to process this structure.

8 21 Data Structures are NOT Created Equal  All have advantages and disadvantages.  Worst ‘algorithm’ that processes data in one data structure may be the best in other case.  Never “poo-poo” a data structure or a seemingly inefficient algorithm!

9 21 Know: Definitions of terms below and have an example…  Database  Record  Field (attribute)  If I should ask for a definition, please recognize that an ‘example’ (drawing or text) is NOT a definition.  A definition must be very unambiguous.

10 21 Object Oriented Programming  Addressed two problems of procedural languages:  Lack of correspondence between the program and the real world, (physical description vs program realization)  The internal organization of the program.  Most real world objects have properties (attributes).  Objects provide certain actions or services on data for clients.  They can carry out a task if sent a ‘message.’

11 21 Examples :  Programs were (largely) ‘procedural.’  Divided into functions, sections, paragraphs, ‘routines.’  Data:  either ‘local’ to one construct (function or procedure) or  ‘global’ to many.  Global Data, No practical way to specify methods that can access a variable and those that cannot.  Result: for global data, all data – even data not needed by particular procedures – was available to all (or most) procedures.  COBOL; Can do in C and others too, if not careful  Recall: Call by Reference; Call by Value??  Frequently a source of inadvertent errors!!!  Know these!!! 

12 21 Objects :  Encapsulate data (attributes, fields, properties)  and  Encapsulate operations ( methods, member functions ) that operate on the data.  Only methods within an object are allowed access to data in that object. (in Java)  (if attributes are given visibility ‘private.’)   An object may be viewed as a real world representation of a real ‘thing’ or ‘noun.’  An object is an instantiation of a class.

13 21 Classes  A class is a generalization of many objects;  A class is a template; an abstraction.  Objects are merely ‘instances’ of classes, but these are real and these are what we process!  We access these objects by referencing them. (References are ‘addresses’ of the objects)  We often create references to objects first and then create the objects themselves.  e.g.  Thermostat therm1, therm2; // references  therm1 = new Thermostat(); // creates the object  therm2 = new Thermostat(); // w therm1 and 2 pointing // to their respective objects.  Consider Listing 1.1 in your book as a Review:

14 21  A good ‘review’ is undertaken in the following code…

15 21  // bank.java // demonstrates basic OOP syntax  class BankAccount  {  private double balance; // account balance why private? What kind of variable is this? Why? // Who has ‘access’ to balance?  public BankAccount ( double openingBalance) // constructor  {  balance = openingBalance; // What is a Constructor?  }  public void deposit ( double amount) // makes deposit  {  balance = balance + amount; // What is amount called? (formally)  // Is this Call by Reference or Call by Value?  } // end deposit // Note ‘scope terminator’  public void withdraw(double amount) // makes withdrawal  {  balance = balance - amount;  }  public void display() // displays balance  {  System.out.println ("balance=" + balance);  }  } // end class BankAccount  class BankApp // Note: this class is still in the same file….  {// Where does execution start?  public static void main(String[] args)  {  BankAccount ba1 = new BankAccount(100.00); // reference and acct object; Other ways to do this?  System.out.print ("Before transactions, ");  ba1.display(); // display balanceWhat is going on here? What do you call this?  ba1.deposit(74.35); // make depositWhat is the called?  ba1.withdraw(20.00); // make withdrawal  System.out.print ("After transactions, ");  ba1.display(); // display balance  } // end main()  } // end class BankApp KNOW: Instance variables; local variables; static (class) variables)

16 21 // bank.java // // demonstrates basic OOP syntax file name or application name or package // name…(more ahead) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class BankAccount { private double balance; // account balance most object data is private public BankAccount(double openingBalance) // constructor Constructor never has a ‘return type’ {// in Javadoc put None. balance = openingBalance; }// end constructor public void deposit(double amount) // makes deposit: four methods (“services” provided // to clients of this object. { balance = balance + amount; }// end deposit public void withdraw(double amount) // makes withdrawal // most methods (services) are { // public. When might they be private? balance = balance - amount; // What is the signature of an object? }// end withdraw public void display() // displays balance { System.out.println("balance=" + balance); }//end display() } // end class BankAccount // I require scope terminators on methods and classes. Note: object ‘encapsulates’ everything about bank account objects; ‘ information hiding’ too. Let’s look at the two Classes:

17 21 class BankApp { public static void main(String[] args) { BankAccount ba1 = new BankAccount(100.00); // create acct // what does this statement do? System.out.print("Before transactions, ");// Explain what this REALLY is! ba1.display(); // display balance // Explain generically what this really is! ba1.deposit(74.35); // make deposit // Explain generically what this really is! ba1.withdraw(20.00); // make withdrawal System.out.print("After transactions, "); // What is this statement? What does it do? ba1.display(); // display balance } // end main() } // end class BankApp  Note the scope terminators Outputs: Before transactions, balance=100 After transactions, balance= …and the second class

18 21 Inheritance and Polymorphism  Had  1. encapsulation  2. information hiding  What is encapsulation? Examples?  What is information hiding? Examples?  Who cares??

19 21 Inheritance and Polymorphism  Inheritance involves  Creation of a class (subclass, derived class, child class…) from a base class (super class, parent, …)  Add features in subclasses (derived classes); override features in base class, etc.  Inheritance is all about reuse!!  Polymorphism  Are different derived classes from a base class.  Methods are said to be ‘polymorphic.’  In practice, polymorphism usually refers to referencing a method (a ‘polymorphic’ method) that will execute a different method for different objects of different derived classes all of which come from the base class. Method name is same; Pointer to object (and thus method body) is different.  Significant facility to support extension, maintainability, and a number of other design features.  Polymorphism is all about design, extension, and reuse.

20 21 Study:  Summary  Go through these materials and the study questions too.  Make sure you understand these. You will see these again shortly.

21 Questions?