10
Programming Programming Languages Languages

ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

Embed Size (px)

Citation preview

Page 1: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

ProgrammingProgramming LanguagesLanguages

Page 2: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

Object-oriented Object-oriented Programming Programming LanguagesLanguagesThis lecture discusses the concept of object-This lecture discusses the concept of object-

oriented programming. The concepts we oriented programming. The concepts we will cover include the notions of object and will cover include the notions of object and classes, patterns for objects, inheritance of classes, patterns for objects, inheritance of operations, the maintenance of control operations, the maintenance of control over dependencies, and the dynamic over dependencies, and the dynamic nature of operations as an essential nature of operations as an essential feature of reuse.feature of reuse.

Page 3: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

• It began in the 1960s with the Simula project, an It began in the 1960s with the Simula project, an

attempt to design a programming language that attempt to design a programming language that extends Algol60 in a way suitable for performing extends Algol60 in a way suitable for performing computer simulations of real-world situations.computer simulations of real-world situations.

• One of the central ideas was to incorporate One of the central ideas was to incorporate the notion of an object,the notion of an object,

Object-oriented programmingObject-oriented programming

• which, similar to a real-world object, is an which, similar to a real-world object, is an entity with certain properties, and with the entity with certain properties, and with the ability to react in certain ways to events. ability to react in certain ways to events.

• Simula influences the development of abstract data Simula influences the development of abstract data type mechanisms and the object paradigm.type mechanisms and the object paradigm.

Page 4: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

• Object-oriented programming languages address Object-oriented programming languages address themselves to two issues in software design:themselves to two issues in software design:

• (1) the need to reuse software (1) the need to reuse software components as much as possible, components as much as possible,

Software Reuse and Software Reuse and IndependenceIndependence

• (2) the need to maintain the independence (2) the need to maintain the independence of different components.of different components.

• extension, restriction, redefinition, extension, restriction, redefinition, abstraction, and "polymorphization“.abstraction, and "polymorphization“.

• There are five basic ways that a software There are five basic ways that a software component can be modified for reuse:component can be modified for reuse:

Page 5: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

• A A text windowtext window can be defined as a can be defined as a windowwindow with some added text to be displayed. Thus with some added text to be displayed. Thus a text window extends a window by adding a text window extends a window by adding data, without necessarily changing the data, without necessarily changing the operations to be performed. operations to be performed.

ExtensionExtension

• As an example of modification by extension, As an example of modification by extension, a a windowwindow is defined on a computer screen is defined on a computer screen as a rectangle specified by its four corners, as a rectangle specified by its four corners, with operations that may include translate, with operations that may include translate, resize, display, and erase.resize, display, and erase.

• This is the extension of the data and/or This is the extension of the data and/or operations. operations.

Page 6: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

• For example, a rectangle has both a length For example, a rectangle has both a length and a width, but a square has length equal and a width, but a square has length equal to width, so one piece of data can be to width, so one piece of data can be dropped in creating a square.dropped in creating a square.

Restriction Restriction

• Restriction is essentially the opposite Restriction is essentially the opposite operation from the extension. operation from the extension.

• This is the restriction of the data and/or operations.This is the restriction of the data and/or operations.

• Restriction is a mechanism that is rarely Restriction is a mechanism that is rarely seen in programming languages seen in programming languages

Page 7: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

• Even if the operations of a new data item Even if the operations of a new data item remain essentially the same, it may be remain essentially the same, it may be necessary to redefine some of them to necessary to redefine some of them to accommodate new behavior. accommodate new behavior.

RedefinitionRedefinition

• This is the redefinition of one or more of the This is the redefinition of one or more of the operations. operations.

• For example, a square is obtained from a For example, a square is obtained from a rectangle, an area or perimeter function may rectangle, an area or perimeter function may need to be redefined to take into account the need to be redefined to take into account the reduced data needed in the computation. reduced data needed in the computation.

Page 8: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

AbstractionAbstraction• This is the collection of similar operations from two This is the collection of similar operations from two

different components into a new component. different components into a new component.

• For example, a circle and a rectangle are For example, a circle and a rectangle are both objects that have position and that can both objects that have position and that can be translated and displayed.be translated and displayed.

• These properties can be combined into an These properties can be combined into an abstract object called a figure,abstract object called a figure,

• which has the common features of circles, which has the common features of circles, rectangles, triangles, and so on. rectangles, triangles, and so on.

Page 9: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

PolymorphizationPolymorphization

• or the extension of the type of data that or the extension of the type of data that operations can apply to.operations can apply to.

• A good example might be that of a print A good example might be that of a print function, which should be applicable to any function, which should be applicable to any variable as long as its value is printable. variable as long as its value is printable.

• Extending the types that an operation applies to Extending the types that an operation applies to can also be viewed as an example of abstraction, can also be viewed as an example of abstraction, where common operations from different types where common operations from different types are abstracted and collected together. are abstracted and collected together.

• There are two kinds of polymorphism: There are two kinds of polymorphism: overloading and parameterized types.overloading and parameterized types.

Page 10: ProgrammingLanguages Programming Languages Object-oriented Programming Languages This lecture discusses the concept of object- oriented programming

Restricting access to internal Restricting access to internal details details

• Restricting access to internal details of Restricting access to internal details of software components is another. software components is another.

• Design for reuse is not the only goal of Design for reuse is not the only goal of object-oriented languages. object-oriented languages.

• Mechanisms for restricting access to internal Mechanisms for restricting access to internal details go by several names:details go by several names:

• Encapsulation mechanisms,Encapsulation mechanisms,

• Information hiding mechanisms, or Information hiding mechanisms, or

• Protection mechanisms. Protection mechanisms.