Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to OOP Mehdi Einali Advanced Programming in Java 1.

Similar presentations


Presentation on theme: "Introduction to OOP Mehdi Einali Advanced Programming in Java 1."— Presentation transcript:

1 Introduction to OOP Mehdi Einali Advanced Programming in Java 1

2 2 agenda Object Oriented Programming History of Programming languages Characteristics of objects Interface Encapsulation

3 3 Object oriented programming

4 4 Abstraction Simplification of complex system via interface(Modeling) Machine language Assembly: an abstraction of the machine language Many languages are abstraction of assembly language Fortran, Basic, C But they still require you to think in terms of the structure of the computer Rather than the structure of the problem

5 5 Different Contexts Problem Space the place where the problem exists such as a business Solution Space the place where you’re implementing that solution such as a computer The effort required to perform this mapping

6 6 Library Problem Suppose you want to write a library program What are the elements of your program? We think about methods and variables…

7 7 Object Oriented Approach OO approach goes a step further Lets the programmer represent problem space elements This representation is general enough The programmer is not constrained to any particular type of problem. The elements in the problem space and their representations in the solution space are referred to as “objects”

8 8 OOP The program is allowed to adapt itself to the lingo of the problem by adding new types of objects when you read the code, you’re reading words that also express the problem. This is a more flexible and powerful language abstraction

9 9 Reuse Student Course Teacher Grant Book Paper Journal Education System Library System Research System

10 10 Change SW system could not change with requirements Maintenance is more expensive than development Avoid cascading changes Increase cohesion / balance coupling Object Orientation

11 11 Advantage of OOP Abstraction Seamless in modeling Best fit to problem domain Reuse Good for Change Extendibility Maintainability Modifiability Testability

12 12 Evaluation of programming languages to OOP

13 13 generation 1 First-generation languages (1954–1958) FORTRAN I Mathematical expressions ALGOL 58 Mathematical expressions Flowmatic Mathematical expressions IPL V Mathematical expressions This first generation of high-order programming languages therefore represented a step closer to the problem space and a step further away from the underlying machine

14 14 Generation 2 Second-generation languages (1959–1961) FORTRAN II Subroutines, separate compilation ALGOL 60 Block structure, data types COBOL Data description, file handling Lisp List processing, pointers, garbage collection Emphasis was on algorithmic abstractions Machines were becoming more and more powerful then more kinds of problems could be automated, especially for business applications read these personnel records first, sort them next, and then print this report A step closer to the problem space and further away from the underlying machine

15 15 generation 3 Third-generation languages (1962–1970) PL/1 FORTRAN + ALGOL + COBOL ALGOL 68 Rigorous successor to ALGOL 60 Pascal Simple successor to ALGOL 60 Simula Classes, data abstraction Advent of transistors and then integrated circuit technology, the cost of computer hardware had dropped dramatically Larger problems could now be solved, but these demanded the manipulation of more kinds of data Support data abstraction describe the meaning of related kinds of data (their type)

16 16 Genertion gap The generation gap (1970–1980) Many different languages were invented, but few endured. However, the following are worth noting: C Efficient; small executable FORTRAN 77 ANSI standardization Creation of literally a couple of thousand different programming languages and dialects Few of these languages survived

17 17 oop Object-orientation boom (1980–1990, but few languages survive) Smalltalk 80 Pure object-oriented language C++ Derived from C and Simula Ada83 Strong typing; heavy Pascal influence Eiffel Derived from Ada and Simula

18 18 Frameworks Emergence of frameworks (1990–today) Visual Basic Eased development of the graphical user interface (GUI) for Windows applications Java Successor to Oak; designed for portability Python Object-oriented scripting language J2EE Java-based framework for enterprise computing.NET Microsoft’s object-based framework Visual C# Java competitor for the Microsoft.NET Framework Visual Basic.NET Visual Basic for the Microsoft.NET Framework

19 19 Topology of 1 st and early 2 nd gen Basic physical building block of all applications is the subprogram (or the paragraph - COBOL) Flat physical structure, consisting only of global data and subprograms An error in one part of a program can have a devastating ripple effect across the rest of the system

20 20 Late 2 nd and Early 3 rd Gen The first software abstraction, now called the ‘procedural’ abstraction Variety of parameter-passing mechanisms Nesting subprogram, theories about control structures, scope and visibility of structures Structured design methods Greater control over algorithmic abstractions Still fails to address the problems of programming-in-the-large and data design.

21 21 Late Third-Generation Larger programming projects meant larger development teams, and thus the need to develop different parts of the same program independently Separately compiled module Need for semantic consistency among module interfaces Most of these languages had dismal support for data abstraction and strong typing, such errors could be detected only during execution of the program.

22 22 Object based and object oriented Procedural abstraction is not enough Data abstraction is important to mastering complexity Data-driven design methods emerged, which provided a disciplined approach to the problems of doing data abstraction in algorithmically oriented languages Theories regarding the concept of a type appeared, which eventually found their realization in languages such as Pascal If procedures and functions are verbs and pieces of data are nouns, a procedure-oriented program is organized around verbs while an object- oriented program is organized around nouns

23 23 Beyond programming languages Enterprise Application Integration(EAI) Service Oriented architecture(SOA)

24 24 OOP vs. Procedural Approach Elements of OOP Objects Message passing between objects Elements of procedural programming Functions Variables Function invocation The way of thinking Thinking about objects and relations Thinking about functions and computer structure

25 25 Object characteristics

26 26 OOP Characteristics Alan Kay summarized five basic characteristics of Smalltalk 1.Everything is an object 2.A program is a bunch of objects telling each other what to do by sending messages 3.Each object has its own memory made up of other objects 4.Every object has a type 5.All objects of a particular type can receive the same messages

27 27 Booch’s description of an Object An object has state, behavior and identity Booch added identity to the description An object (may) have internal data which gives it state An object (may) have methods to produce behavior And each object can be uniquely distinguished from every other object Each object has a unique address in memory

28 28 interface

29 29 Interface Each object can satisfy only certain requests The requests you can make of an object are defined by its interface The type is what determines the interface

30 30 Representation of a light bulb

31 31 Person in an Education System

32 32 New names in OOP Function  Method, Service Variable  Property, State

33 33 encapsulation

34 34 Encapsulation Commercial products are encapsulated Remote control TV Cell phone They are Black Boxes Hidden Implementations Public interface

35 35 encapsulate

36 36 Why Encapsulation? Simplified use Even for the producer Open implementation  bad use Hiding the implementation reduces bugs It is more beautiful!

37 37 Object Encapsulation Encapsulation of a problem-space concept into a class of objects Define interface Hide the implementation Black box The client may see the implementation But can not use it directly This is better even for the producer (programmer)

38 38 Access Control Access to some parts of the class is restricted Public and Private area of the class The client of a class can use only public area Public area = class interface Public methods Public variables

39 39 Example: Rectangle Lets encapsulate a rectangle What is a rectangle? An object Which has length and width (properties) Lets you specify its length and width Can calculate its area and perimeter

40 40 Class Declaration public class Rectangle { private int width, length; public void setWidth(int w) { width = w; } public void setLength(int l) { length = l; } public int calculateArea(){ return width*length; } public int calculatePerimeter(){ return (width+length)*2; } Private area: hidden implementation Public area : the interface

41 41 How to Use Rectangle? Rectangle rect = new Rectangle(); rect.setWidth(2); rect.setLength(7); System.out.println(rect.calculateArea()); System.out.println(rect.calculatePerimeter()); Object creation or instantiation

42 42 Grady Booch Booch Method Three Amigos(1994-95) Ivar Jacobson Object Modeling Technique(OMT) Rumbaugh Process Objectory Unified Modeling Language(UML) Unified Process(UP) Object Oriented Analysis and Design-3rd edtion(2007)

43 43 end


Download ppt "Introduction to OOP Mehdi Einali Advanced Programming in Java 1."

Similar presentations


Ads by Google