1 University of Utah – School of Computing Computer Science 1021 "Object-Oriented Programming"

Slides:



Advertisements
Similar presentations
The Problem Decomposition of programs in terms of classes and in terms of crosscutting concerns are both useful, but languages based on source files allow.
Advertisements

AP Computer Science A – Healdsburg High School 1 Unit 3 - Classes and Objects - Example.
1 University of Utah – School of Computing Computer Science 1021 "Programming with Style"
Introduction to Information and Computer Science Computer Programming Lecture e This material (Comp4_Unit5e) was developed by Oregon Health and Science.
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-1: Classes and Objects reading: self-checks: Ch. 8 #1-9 exercises:
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Computer Science 1620 Function Scope & Global Variables.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
C++ Classes in Depth. Topics Designing Your Own Classes Attributes and Behaviors Writing Classes in C++ Creating and Using Objects.
CS 201 Functions Debzani Deb.
CS 106 Introduction to Computer Science I 03 / 17 / 2008 Instructor: Michael Eckmann.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
CS 106 Introduction to Computer Science I 04 / 13 / 2007 Friday the 13 th Instructor: Michael Eckmann.
Object Oriented Programming CS160 - OOP. Objects Objects are a Objects are a way to organize and conceptualize a program as a set of interacting objects.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA Prof. Dr. Paulo Brasko Ferreira Fall 2014.
Introduction to Information and Computer Science Computer Programming Lecture d This material (Comp4_Unit5d) was developed by Oregon Health and Science.
Functions and subroutines – Computer and Programming.
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Object Oriented Programming … and other things you need to program in java.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
PROCESSING Methods. Objectives Be able to define methods that return values Be able to define methods that do not return values Be able to use random.
1 University of Utah – School of Computing Computer Science 1020 "Object-Oriented Programming"
1 3/2/05CS250 Introduction to Computer Science II Composition and friend Functions.
Designing Programs and the Role of Functions Objectives Solve a few simple programs, emphasizing the steps involved in the process. Introduce the concept.
CS122 Engineering Computation Lab Lab 2 Bruce Char Department of Computer Science Drexel University Spring 2011.
Abstraction ADTs, Information Hiding and Encapsulation.
Object Oriented Programming A new way of thinking.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
CS0007: Introduction to Computer Programming Classes: Documentation, Method Overloading, Scope, Packages, and “Finding the Classes”
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 5.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
Direct Variation 2.4. Big idea… 5280ft=1mile. There will always be the same number of feet in a mile, so they are “directly proportional”
Coming up: Inheritance
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
Computer Science I Variables. Methods. Classwork/Homework: Re-do or do new drawing using variables & function(s). Zip folder and upload to Moodle dropbox.
Lawrence Snyder University of Washington, Seattle © Lawrence Snyder 2004 Functional Abstraction Reduces Complexity.
The problem that needs to be solved is if a computer career is for me.
CS 106 Introduction to Computer Science I 03 / 22 / 2010 Instructor: Michael Eckmann.
Classes CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
Journal Expectations. Take ownership of your journal it is a personal log of what you have learned the entire 7 th grade year. These are your thoughts,
The Red Group’s Week. Wheel and Axle A wheel and axle is a simple machine made of two circular and cylindrical objects fastened together that rotate about.
Introduction to Programming Lecture 6. Functions – Call by value – Call by reference Today's Lecture Includes.
COMP Information Hiding and Encapsulation Yi Hong June 03, 2015.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Introduction to OO Programming Andy Wang Object Oriented Programming in C++ COP 3330.
Andrew(amwallis) Classes!
Web Technology Solutions
Classes and OOP.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Chapter 16 – Programming your App’s Memory
Class Variables We’ve seen how to add extra subroutines into our programs Can be accessed from within one another We can also add variables that are “global”
Chapter 4 Procedural Methods.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Lecture 11 C Parameters Richard Gesick.
COMP 110 Information hiding and encapsulation
Chapter 7 Procedural Methods.
COP 3330 Object-oriented Programming in C++
Fundaments of Game Design
CS 1054: Lecture 2, Chapter 1 Objects and Classes.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

1 University of Utah – School of Computing Computer Science 1021 "Object-Oriented Programming"

University of Utah – School of Computing University of Utah 2 Procedural Programming What we've done so far: -variables -methods that operate on those variables

University of Utah – School of Computing University of Utah 3 Large-Scale Programming Hard to write BIG programs using procedural programming techniques WHY?

University of Utah – School of Computing University of Utah 4 Problem #1 Global Variables!

University of Utah – School of Computing University of Utah 5 Problem #2 Limits of human comprehension

University of Utah – School of Computing University of Utah 6 Problem #3 Brittle dependencies

University of Utah – School of Computing University of Utah 7 Conceptual Leap 1. Dividing a large job into small methods 2. Dividing several large jobs (or concepts) into multiple classes!

University of Utah – School of Computing University of Utah 8 Analogy Toy blocks

University of Utah – School of Computing University of Utah 9 Classes Have variables and methods Or "attributes" and "behaviors"

University of Utah – School of Computing University of Utah Example Modify our circle drawing program What attributes does a circle have?

University of Utah – School of Computing University of Utah Circle class public class Circle { int x, y; int radius; Color color; }

University of Utah – School of Computing University of Utah Circle class What do you want to do with a circle? -Draw it? -Move it? -Resize it? -Calculate area? -Calculate circumference?

University of Utah – School of Computing University of Utah Methods class Circle { int x, y; int radius; Color circle; void draw(Graphics g) { //do stuff } double computeArea() { //do stuff }

University of Utah – School of Computing University of Utah How to draw a circle? void draw(Graphics g) { }

University of Utah – School of Computing University of Utah How to find the circle's area? double computeArea() { }

University of Utah – School of Computing University of Utah Classes vs. Objects A class is just the "definition" or the code An object is when you make a variable whose type is a class Example: - JPanel p; - p = new JPanel();

University of Utah – School of Computing University of Utah Block example revisited Wrap up all attributes and methods inside a class Easier to manage! Safer too? Why?

University of Utah – School of Computing University of Utah Car example You can drive a car without knowing how it works internally "public" user interface: -steering wheel -gas/brake pedals -ignition

University of Utah – School of Computing University of Utah Car example You can drive a car without knowing how it works internally "private" inner workings -don't know, don't care

University of Utah – School of Computing University of Utah "public" explained public methods and variables -Other classes can use them So far, this is all we've used

University of Utah – School of Computing University of Utah "private" also! private methods and variables -Other classes may NOT access them Used for internal data

University of Utah – School of Computing University of Utah A General Rule private variables -they are our internal data public methods -they are how other classes use our class

University of Utah – School of Computing University of Utah Circle class revisited class Circle { private int x, y; private int radius; private Color circle; public void draw(Graphics g) { //do stuff } public double computeArea() { //do stuff }

University of Utah – School of Computing University of Utah Why public and private? Secrecy? No. Simplicity? Yes. Order? Yes. Maintainability? Yes.

University of Utah – School of Computing University of Utah Examples Math.random() JPanel.add()

University of Utah – School of Computing University of Utah Tomorrow Work on "Circle" example together

University of Utah – School of Computing University of Utah Reminder Homework 5 is due tomorrow, not Wednesday, due to Fourth of July Office hours today from 9:45 to noon

University of Utah – School of Computing University of Utah Request for Comments Please fill out online survey!