Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Slides:



Advertisements
Similar presentations
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Advertisements

Python Objects and Classes
Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Informática II Prof. Dr. Gustavo Patiño MJ
OOP - Object Oriented Programming Object Oriented Programming is an approach to programming that was developed to make large programs easier to manage.
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 & Objects Computer Science I Last updated 9/30/10.
Introduction to Object Oriented Programming Java.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
OBJECT-ORIENTED PROGRAMMING. What is an “object”? Abstract entity that contains data and actions Attributes (characteristics) and methods (functions)
Programming Language Paradigms: summary. Object-oriented programming Objects are the fundamental building blocks of a program. Interaction is structured.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
1 Basic Object-Oriented Concepts  Object-Oriented Paradigm What is an Object?  What is a Class?  Constructing Objects from a class Problem Solving in.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 1 Introduction to Object-Oriented Programming and Software Development.
C++ fundamentals.
BACS 287 Basics of Object-Oriented Programming 1.
CPT 140 Programming Constructs1 OBJECT ORIENTED TECHNOLOGY Terminology and Basic Concepts.
Object Oriented Software Development
OOP- OBJECT OBJECT PROGRAMMING By KRATI SHARMA 02 XI-B ✏✏✏✏ ☺☻☺☻☺☻☺ ✏✏✏✏
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
Introduction to Object-oriented programming and software development Lecture 1.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
BCS 2143 Introduction to Object Oriented and Software Development.
CIT 590 Intro to Programming Style Classes. Remember to finish up findAllCISCourses.py.
An Object-Oriented Approach to Programming Logic and Design
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Chapter 11 Introduction to Classes. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. Code Listing 11.1.
11 Chapter 11 Object-Oriented Databases Database Systems: Design, Implementation, and Management 4th Edition Peter Rob & Carlos Coronel.
Classes 1 COMPSCI 105 S Principles of Computer Science.
Chapter 12 Object Oriented Design.  Complements top-down design  Data-centered view of design  Reliable  Cost-effective.
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
CLASSES Python Workshop. Introduction  Compared with other programming languages, Python’s class mechanism adds classes with a minimum of new syntax.
Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section on UML: look at class diagrams but.
Object-Oriented Programming with Java Lecture 1: Introduction Autumn, 2007.
ITEC 3220A Using and Designing Database Systems Instructor: Gordon Turpin Course Website: Office: CSEB3020.
Learners Support Publications Object Oriented Programming.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Overview The Basics – Python classes and objects Procedural vs OO Programming Entity modelling Operations / methods Program flow OOP Concepts and user-defined.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Object-Oriented Programming Chapter Chapter
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
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.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Classes, Interfaces and Packages
Basic Concepts of OOP.  Object-Oriented Programming (OOP) is a type of programming added to php5 that makes building complex, modular and reusable web.
Lecture 2 Intro. To Software Engineering and Object-Oriented Programming (2/2)
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
CMSC201 Computer Science I for Majors Lecture 25 – Classes
OOP - Object Oriented Programming
Object-Oriented Programming Concepts
CHAPTER 5 GENERAL OOP CONCEPTS.
The Object-Oriented Thought Process Chapter 1
OOP What is problem? Solution? OOP
OBJECT ORIENTED PROGRAMMING overview
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Oriented Concepts
Object-oriented programming
PROGRAMMING PARADIGMS
Teach A-Level Computer Science: Object-Oriented Programming in Python
Introduction to Object-Oriented Programming
Workshop for Programming And Systems Management Teachers
Object-Oriented Programming
Programming Paradigms
A Level Computer Science Topic 6: Introducing OOP
Presentation transcript:

Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg

PA09 New homework - word clouds!

Programming Styles Up until today, we have been programming in a procedural programming style  Series of computational steps to be carried out  We do this by writing functions that operate on data structures This style of programming is suitable for smaller programming tasks

Programming Styles Classes are part of Object Oriented Programming (OOP) OOP is a way to think about “objects” in a program (such as variables, functions, etc). A program becomes less a list of instructions and more a set of objects and how they interact.  Models the “real world” where objects (entities) work together to accomplish tasks

Responding to “Messages” As a set of interacting objects, each object responds to “messages” sent to it. The interaction of objects via messages makes a high level description of what the program is doing. Start!

Everything in Python is an Object In case you hadn’t noticed, everything in Python is an object. Thus Python embraces OOP at a fundamental level. This is in contrast to other programming languages  C is completely procedural  Java is OOP but has some partial non-objects

OOP Helps in Software Engineering Software engineering is the discipline of managing code to ensure its long-term use. We’ve already seen some code reuse  Counters, accumulators  Can write general functions We will find the same thing with objects  Some basic objects are even easier to reuse  Strings, list, dictionaries, …

More Refactoring Hiding the details of what the message entails means that changes can be made to the object and the flow of messages (and their results) can stay the same. Thus the implementation of the message can change but its intended effect stays the same. This is encapsulation.

OOP Principles Encapsulation: hiding design details to make the program clearer and more easily modified later. Modularity: the ability to make objects “stand alone” so they can be reused (our modules). I.e. the math module.

OOP Principles Inheritance: create a new object by inheriting (like parent to child) many object characteristics while creating or over-riding for this object. Polymorphism: (hard) Allow one message to be sent to any object and have it respond appropriately based on the type of object it is.  Where have we seen this already?? 10

Class versus Instance One of the harder things to understand is what a class is and what an instance of a class is. Consider the analogy of the cookie cutter and a cookie.

Class versus Instance The cutter is a template for “stamping out” cookies, the “cookie” is what is made each time the cutter is used. One template can be used to make an infinite number of cookies, each one just like the other. No one confuses a cookie for a cookie cutter, do they?

Same in OOP You define a class as a way to generate new instances of that class. Both the instances and the classes are themselves objects. The structure of an instance starts out the same, as dictated by the class. The instances respond to the messages defined as part of the class.

Why a Class? We make classes because we need more complicated, user-defined data types to construct instances we can use. Each class has potentially two aspects:  the data (types, number, names) that each instance might contain  the messages that each instance can respond to

A First Class Say we need to make a new university information system  What is this?

A First Class In a university information system, we need information about  Students  Faculty  Courses  Transcripts Python does not have these We need to create our own definitions of what a “student” is!

A First Class What should a bundle of information called a “student” should know about in our code?  Name  Student ID  What else…? 17

A First Class What should a bundle of information called a “student” should know about in our code?  Name  Student ID  What else…? Could put this information in a tuple, but what’s missing? 18

A First Class What should a bundle of information called a “student” should know about in our code?  Name  Student ID  What else…? Could put this information in a tuple, but what’s missing?  It would be nice to pass message to a student object, and have that student object operate on its own data 19

A sample class class Student(object): """Simple Student class.""" def __init__(self,first='', last='', id=0): # init instance self.firstNameStr = first self.lastNameStr = last self.idInt = id def __str__(self): # string representation for printing return "{} {}, ID:{}".format\ (self.firstNameStr, self.lastNameStr, self.idInt)

Constructor When a class is defined, a function is made with the same name as the class This function is called the constructor. By calling it, you can create an instance of the class. We can affect this creation (more later), but by default Python can make an instance.

A Class is a New Type >>>myLst = [1, 2, 3] type(myLst) => type >>>myStr = ‘abc’ type(myStr) => type >>>s1 = Student(“Jane",“Doe",12345) type(s1)

Instance Knows its Class Because each instance has as its type the class that it was made from, an instance “remembers” its class. This is often called the “instance-of” relationship.

“Dot” Reference We can refer to the attributes of an object by doing a “dot” reference, of the form: object.attribute The attribute can be a variable or a function. It is part of the object, either directly or by that object being part of a class.