Introduction to Computer Science Object Oriented Programming for ESL first year university students.
Size: 30.85 MB
Language: en
Added: Apr 25, 2024
Slides: 44 pages
Slide Content
Introduction to OOP CS AC W L 7 By Profess o r . E d mond
Objectives/Goals In t roduc t ion to basi c con c e pt s o f objec t - oriented programming. • Terminology of object-oriented programming and syntax. Practical application s o f objec t - orient e d programming. To practice coding and debugging skills.
Agenda
Introduction • A Brief Programming History OOP Classes & Objects
5 Computer Programming An algorithm is a step-by-step process. A computer program is a step-by-step set of instructions for a computer. Every computer program is an algorithm.
Computer Programming The history of computer programming is a steady m o v e a w a y f ro m machin e - ori e nte d view s of programming towards concepts and metaphors that more closely reflect the way in which we ourselves see & understand the world
Programming languages allow programmers to develop software. How many major language families are there? The three major families of languages are: Machine languages Assembly languages High-Level languages Computer Programming Languages
Machine Languages Comprised of 1s and 0s The “ native ” language of a computer Difficult to program – one misplaced 1 or will cause the program to fail. Example of code: 1110100010101 10111010110100 111010101110 10100011110111
Assembly Languages Assembly languages are a step towards easier programming. Assembly l a ngua g es a r e compri s ed o f a set of el e me n tal commands which are tied to a specific processor. Assembly language code needs to be translated to machine language before the computer processes it. Example: ADD 1001010, 1011010
High-Level Languages High-level languages represent a giant leap towards easier programming. T he syntax of HL languages is similar to English. Example: grossPay = basePay + overTimePay Interpreter – Executes high level language programs without compilation. Historically, we divide HL languages into two groups: Procedural languages Object-Oriented languages (OOP)
Procedural Languages Earl y h i g h - le v el langua g es ar e typical l y called proc e d ural l anguages. Proc e dural lang u a g es ar e c har a cter i zed b y s equenti a l sets of linear commands. The focus of such languages is on structure . Ex a mple s include C , COBOL , F o r tran, LIS P , Perl, H T ML, VBScript
Object-Oriented Languages The focus of OOP languages is not on structure, but on modeling data . Programmers code using “ blueprints ” of data models called classes . E x ampl e s of OO P l a ngua g es include C++, Visua l B a si c . NET and Java.
Early programming languages Classic C Pa sc a l Algol68 B C PL Fortran COBOL Algol60 P L \ 1 1950s 1960s 1970s Simula Lisp Red ==major commercial use Blue ==will produce important “offspring”
Modern programming languages Object Pascal C++ Java95 C# Ada98 C++98 Java04 C++0x Python Lisp Smalltalk Fortran77 Ada Ei f fel Si m ula67 P H P C89 Pascal C O B O L89 P E RL Visual Basic CO B OL04 Java scr i pt
Simula is a name for two simulation programming languages, Simula I and Simula 67, developed in the 1960s at the Norwegian Computing Center in Oslo, by Ole-Johan Dahl and Kristen Nygaard. Simula is considered the first object-oriented programming language. Simula was designed for doing simulations, and the needs of that domain provided the framework for many of the features of object-oriented languages today.
Introduction • A Brief Programming History OOP Classes & Objects
OOP OOP is mainly a program design philosophy. O OP uses a different set of programming languages than old proced ural programming languages ( C, Pascal , etc.). Everything in OOP is grouped as self sustainable " objects " . Hence, you gain re-usability by means of four main object-oriented programming concepts.
In OOP programmers define not only the data type of a data structure, but also the ty pes of operations/methods (functions) that can be applied to the data structur e. In this way, the data structure becomes an object that includes both data and functions (methods) in one unit. In addition, programmers can create relationships between one object and another. For example, objects can inherit characteristics from other objects. OOP
OOP Languages · Pure OO Languages Eiffel, Actor, Emerald, JADE, Obix, Ruby, Python, Scala, Smalltalk, Self. · Hybrid OO Languages Del p hi/Obje c t P ascal , C++, J a v a , C#, V B . N E T , P as c al , Vi s ual Basic, MATLAB, Fortran, Perl, COBOL 2002, PHP, ABAP, Ada 95.
OOP K ey idea in object-oriented: Th e r eal world ca n b e “ a c c u r a t e ly” d escri b ed a s a co l lecti o n of objects that interact .
OOP Basic Terminology Object - usually a person, place or thing ( a noun ) Method - an action performed by an object ( a verb) Property or attribute - Charac t eristics o f c e r tain obje c t . Class - a category of similar objects (such as automobiles ), does not hold any values of the object ’ s attributes/properties
Introduction A Brief Programming History OOP Classes & Objects
Classes and Objects A class is a prototype, idea, and blueprint for creating objects. An object is an instance of a class. F o r exampl e , i n J av a w e d efine classe s , w hi c h i n tu r n are used to create objects A class has a constructor for creating objects Class is composed of three things: its name, attributes/properties, and methods.
Classes (objects) Objects: Instances of the class Methods: Functions of class Cl a ss Instance Properties: Belong to the object Class Properties: Belong to the class
27 Classes (objects) A class is a definition of objects with the same properties and the same methods.
28 Classes Example
Almost everything in the world can be represented as an object A flower, a tree, an animal A student, a professor A desk, a chair, a classroom, a building A university, a city, a country The world, the universe A s ubje c t su c h a s C S , I S , Math , H is t o r y , … An information system, financial, legal, etc..
An object is an instance of a class. What Is an Object, again?
Informally, an object represents an entity, either physical, conceptual, or software. Physical entity Conceptual entity Software entity More about objects T ruck Chem i c al Process L i n ke d L ist
More formal definition of an “ Object ” An object is a computational entity that: Encapsulates some state Is able to perform actions, or methods , on this state Communicates with other objects via message passing
Classes & Objects P R O P E R TY Do something: function & procedure “ X-CAR” P R O P E R TY Plate no: AD47483 Co l o r : B l u e Ma n u f a A c t u t r r i e e b r u : t M e o e r c s e t d a t e e s Model: CLK Gear type: Automatic M o v e M s f o r E wa T rd H O D Moves backward Moves right M o v es l eft S S t t o o p ps s
Classes & Objects hour minu t e void addMinutes( int m ) Time inTime Attrib ute s : hour = 8 minute = 30 Methods: void addMinutes(int m) outTime Attributes: hour = 17 minute = 35 Methods: void addMinutes(int m) class obje c ts
35 Class/Object Ea c h copy of an o bjec t from a pa r tic u lar class i s called a n i n s t a n ce of t h e class.
36 The act of creating a new instance of an class is called instantiation. Class/Object
In short… An Object is a Class when it comes alive! Homo Sapien is a class , John and Jack are objects Animal is a class “Snowball” the cat is an object V ehic l e is a class M y neighbor' s BMW is a n object Galaxy is a class , the Mi l k y W a y is an object
CLASS OBJECT Class is a data type Object is an instance of Class. It generates OBJECTS It gives life to CLASS Does not occupy memory location It occupies memory location. It cannot be manipulated because it is not available in memory (except static class) It can be manipulated. T E C HNI C AL C O N T RAS T B E T W E E N O B J EC T S & C L AS SES Object is a class in “runtime”
Objects Need to Collaborate! Objects are useless unless they can collaborate together to solve a problem. Each o bj e ct i s respo n si b le for it s own b e h a vior and status. No one object can carry out every responsibility on its own. How do objects interact with each other? They interact through messages.
The OrderEntryForm wants Order to calculate the total NOK value for the order. Example of Object Interaction OrderEntryForm Order orderID date s a lesTo t a l tax shipDate calculateOrderTotal() The class Order has the responsibility to calculate the total NOK value. M e ss a g e