Object Oriented Programming Some Interesting Genes.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Department of Computer Engineering Faculty of Engineering, Prince of Songkla University 1 5 – Abstract Data Types.
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.
Object-Oriented Application Development Using VB.NET 1 Chapter 8 Understanding Inheritance and Interfaces.
Classes & Objects Computer Science I Last updated 9/30/10.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented PHP (1)
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
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.
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
Use of and Using R as an Object Oriented Language John James
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Object Oriented Programming
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Introduction to Object-Oriented Programming Lesson 2.
Lecture 2: Review of Object Orientation. © Lethbridge/La ganière 2005 Chapter 2: Review of Object Orientation What is Object Orientation? Procedural.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Testing in OO Environment The reasons for testing is not any different for any of the design and implementation methodologies, including OO methodology.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
The Object-Oriented Thought Process Chapter 03
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
OOP - Object Oriented Programming
CompSci 280 S Introduction to Software Development
Object-Oriented Design
Programming paradigms
Object-Oriented Programming Concepts
Classes (Part 1) Lecture 3
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Programming Logic and Design Seventh Edition
Classes and OOP.
Review: Two Programming Paradigms
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
Lecture 2 of Computer Science II
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
INTRODUCTION TO OOP Objective:
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
The Object-Oriented Thought Process Chapter 08
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Object Oriented Programming
Inheritance Basics Programming with Inheritance
Object-oriented Design in Processing
MSIS 670 Object-Oriented Software Engineering
Teach A-Level Computer Science: Object-Oriented Programming in Python
Object-Oriented Programming
Week 6 Object-Oriented Programming (2): Polymorphism
Why Object-oriented Programming?
Object oriented vs procedural programming
Advanced Java Programming
Computer Programming with JAVA
Java – Inheritance.
Object-Oriented Programming
Object-oriented Design in Processing
Defining Classes and Methods
COP 3330 Object-oriented Programming in C++
Introduction to Data Structure
Object-Oriented Programming
Object-oriented Design in Processing
Review of Previous Lesson
Object-Oriented PHP (1)
Use Case Analysis – continued
Agenda Software development (SD) & Software development methodologies (SDM) Orthogonal views of the software OOSD Methodology Why an Object Orientation?
HFOOAD Chapter 5 Interlude
Object-oriented Design in Processing
C++ Object Oriented 1.
Creating and Using Classes
Presentation transcript:

Object Oriented Programming Some Interesting Genes

Object Oriented Programming A Brief Encounter

What Abstract Data Types Classes Objects Methods Inheritance Polymorphism

Why Productivity increase Better code Reusable code Easier to model real things

Object Oriented Design one identifies real objects and the operations on them that are interesting. these operations can then by systematically implemented. for example: we might have pdf’s and cdf’s as different objects. methods might be means, median, maxima and so on.

Object Oriented Design a basic principle (or perhaps hope) is that by faithfully representing the objects we get easier to implement functions. if a cdf object knows how to answer all the cdf questions then it is more useful. if, instead, the cdf is implemented as two vectors (xpos and ypos), it is harder for others to use it.

Three big ideas Abstraction: think only about the components of the problem that are important. Encapsulation: keep the means used to produce the result secret. Other programs get to see only what you want them to. Modularity: group related services into a module with a well defined interface. Other programs should rely only on the interface.

ADT’s we usually write programs to manipulate data data can almost always be represented in many different ways we don’t want our program to depend on the representation of the data an abstract data type provides with a mechanism to avoid a dependence on representation

ADTs a point in the plane can be represented either in terms of its x and y coordinates or in terms of r and  if we write a program that assumes one form or the other then we cannot easily change (and cannot easily use data obtained in different ways) our representation.

ADTs if instead we employ the rather simple tactic of only accessing the data through a function (a macro in many languages) then we can make the access independent of the representation. have a look at the R code in ~rgentlem/Rexamples/xy.R

Classes A class is a specification. It generally consists of some slots and some functions or methods that act on those slots. The slots represent values that are intrinsic to the class. There are many different classes that can represent a single ADT.

Classes Consider a triangle. If we know the lengths of the three sides then we know all about the triangle. So we could implement triangles as objects with three slots: the lengths of each side. We could also implement them as classes with 2 side slots and the angle between the two.

Classes Why would I prefer one implementation over the other? (Basically efficiency) An operation that we might want to perform on a triangle is finding its area. Should we make area a slot? Should we compute it each time it is needed?

Instances Once I have defined the class I need to obtain some objects that are of that class. These are called instances. And one usually says something like instantiate. All programming is done on instances of a class.

Some Subtleties Much of the usefulness of object oriented programming comes from the fact that different instances have different values for the slots. Sometimes we want there to be a slot that has the same value for all instances. This is a class slot (not all OO systems have this).

Objects One definition of an object is that it is a set of operations that share a state. The state consists of one or more values that can only be viewed and modified by operations belonging to the object. The state information is available through the slots.

Objects Some implementations allow direct access to the slots (usually for efficiency) but this can break the data abstraction. In other implementations one can only access slots through accessor functions. Then the implementation can change but I need to only change the accessors, not all my code.

Classes vs Objects an object is a specific entity that exists at run time a class is a static entity that exists in the program code a class describes how to create an object (and in some languages how to interact with that object)

Instances/Objects We instantiate an object with a call to a constructor. Usually it has a nice name like new. x = new(“circle”, r=3.3) Now x is an instance of the circle class. The next step is to think about functions that operate on circles (or more properly instances of the circle class).

Methods A method is a function. But it is a special type of function. Methods act on instances. The argument list for a method is often referred to as a signature. The types of the arguments to a method are used to determine which method should be called.

Methods Methods can have single dispatch. That means that the appropriate method is determined by using a single argument. This is the system used in the S class system. There it is the class of the first argument that is used. For multiple dispatch we want to use all (or many) of the arguments to determine the appropriate method. (S4 methods).

Methods A method is simply a function that has been called from a generic. In many systems it is not possible to call a method directly (and usually it is not a good idea in any system). Accessing slots directly breaks the notion of an ADT.

Programming let’s return to the code in xy.R. in S4 classes there are no accessor functions created by default you must write your own, this is what I have done using Xpos and Ypos can you see a problem with taking that approach?

Problem Why do I have to have Xpos.xy and Xpos.rt? I really just want Xpos! This is where generic functions come in. They basically act as dispatchers. The mechanisms used to determine which method (we can think of Xpos.xy and Xpos.rt as methods) differ between languages.

Generic Functions a generic function is a dispatcher it determines the type of arguments and looks for a method that will match those arguments. that method is then invoked with the arguments used for the generic function.

Costs so what does this cost? it tends to be slower (this does not have to be true) in terms of execution time the burden goes from programming to design (often a good thing).

NextMethod in most (but not all) languages there is a concept of the next method that would be appropriate (after the current method). In the S3 class system there is a NextMethod function. In the S4 object system it is being developed.

Why bother? you know you are only going to write small programs it’s easier to learn good style on small programs small programs have a tendency to grow into large programs small program, written well, can be used as components in large programs