Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.javacup.ir Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.

Similar presentations


Presentation on theme: "Www.javacup.ir Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP."— Presentation transcript:

1 www.javacup.ir Sadegh Aliakbary

2 Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP is clearly noted as the source in the used case. JAVACUP shall not be liable for any errors in the content, or for any actions taken in reliance thereon. Please send your feedback to info@javacup.irinfo@javacup.ir 2

3 Agenda Object Oriented Programming Characteristics of objects Interface Encapsulation 3

4 Abstraction Machine language Assembly: an abstraction of the machine language Many languages are abstraction of assembly language Fortran, Basic, C Big improvement But they still require you to think in terms of the structure of the computer Rather than the structure of the problem JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source4

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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source5

6 Library Problem Suppose you want to write a library program What are the elements of your program? We think about functions and variables… JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source6

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” JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source7

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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source8

9 Object Oriented Languages Smalltalk The first successful object-oriented language One of the languages upon which Java is based Java C++ C## JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source9

10 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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source10

11 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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source11

12 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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source12

13 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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source13

14 Representation of a light bulb: JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source14 UML Diagram

15 Person in an Education System JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source15

16 New names in OOP Function  Method, Service Variable  Property, State JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source16

17 Encapsulation Commercial products are encapsulated Remote control TV Cell phone They are Black Boxes Hidden Implementations Public interface JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source17

18 Why Encapsulation? Simplified use Even for the producer Open implementation  bad use Hiding the implementation reduces bugs It is more beautiful! JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source18

19 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) JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source19

20 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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source20

21 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 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source21

22 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; } JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source22 Private area: hidden implementation Public area : the interface Class Declaration

23 How to Use Rectangle? Rectangle rect = new Rectangle(); rect.setWidth(2); rect.setLength(7); System.out.println(rect.calculateArea()); System.out.println( rect.calculatePerimeter() ); JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source23 Object creation or instantiation

24 JAVACUP.ir Contents redistribution is allowed if JAVACUP is noted as the source24


Download ppt "Www.javacup.ir Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP."

Similar presentations


Ads by Google