Presentation is loading. Please wait.

Presentation is loading. Please wait.

OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.

Similar presentations


Presentation on theme: "OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really."— Presentation transcript:

1 OO in Context Lecture 13: Dolores Zage

2 Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really different from those of yesteryear. Many programmers think they understand OO programming but do not. –For many, the term has become synonymous with the concept of encapsulation. However OO means more than just combining data and subprograms into a single module. Many non-programmers are held hostage to the OOP mystique

3 Introduction What is object-orient programming really? Is it any good? Is it really good? Is it difficult? How will you know it when you see it? Is OO programming a single thing, or does it come in stages?

4 First Fundamental Types are first fundamental notion for OOP. A type denotes a kind of “noun”, and OOP is about nouns or things rather than verbs. That is where the word “object” comes in.

5 Second Fundamental A type definition is a means of defining new kinds of types, or if you like, new kinds of objects. A programming language has a fixed number of built-in types, and a type definition is a way of introducing new kinds of objects that are more related to an application at hand

6 Third Fundamental To define a new type we usually need to define what kinds of actions we can do with new kinds of objects These “operations” go with that type To write an OO program, we need to group everything about a new type together.

7 Fourth Fundamental We would like to able to say that a given section of a program defines everything about type. We would also like to able to define as many objects of the type as we want. This means we would like to have a special kind of program unit just for objects of a given type

8 Fifth Fundamental We need to deal with growth and change with OOP it is important to able to extend a program in a convenient way. This leads to inheritance Inheritance is a key issue in reusing and adapting existing software It is also the greatest source of errors in OO programs according to recent research

9 Series of Ideas As we have seen through the 5 fundamentals, OOP can be viewed as a series of ideas that relate to a certain approach to programming We do NOT need to have these ideas explicitly in language to achieve OOP

10 A Systematic Presentation of OOP Types Private Types Abstraction Composite Types Type Definitions OperationsOverloadingEncapsulation Information Hiding Abstract Data Types Classes StateInheritanceDynamic Binding PolymorphismRelated Issues

11 OO Type Terms Type - a set of objects and the operations on the objects Composite Type - A type whose values have components Class - A type (period). Instance - An object, - a member of a class or type Overloading - use of the same operator with different types (or number) of arguments

12 Programming Language Types Provide a few basic types that the programmer must use to define meaningful computations on a class of real world object How would you represent a phone number? As a float? Note that this is only used for identification and operations such as +-/* are meaningless Then what? How would you represent a deck of cards?

13 OO Module Terms Encapsulation - Grouping of essential characteristics, e.g., all about commands or all about decks of cards Abstraction - Hiding of details that do not contribute to essential characteristics Information Hiding - Restricting the visibility of an object, variable, or an operation to the implementation part of a module

14 The Package Stack Encapsulation and Abstraction Package Stack is const Max_Stack_Size :=100 type stack_structure is record … procedure INITIALIZE_STACK(S: stack_structure); procedure Push(S:stack_structure; item:integer); procedure Pop(S:stack_structure; item:integer); Information Hiding Package Stack is procedure INITIALIZE_STACK; procedure Push(item:integer); procedure Pop(item:integer); Encapsulation - group all the stuff that pertains to a stack together Abstraction - only the header is given, the code is defined elsewhere (body) we are abstracting out the the essential properties Stack is not even visible to the user!

15 Software Reuse - Inheritance Constructor - a procedure that initializes an object, e.g. by allocating storage or setting a local state Destructor- a procedure that cleans up after an object is no longer used Inheritance - deriving a new type or class form an existing types or class multiple inheritance - deriving a type from more than one parent type polymorphism - use of the same name for an operation whose meaning depends upon the types of its arguments, e.g. procedure draw to draw various kinds of shapes or objects. The term has an implication that the different types form a hierarchy.

16 OOP Designing good classes is hard because designing good types is hard What kind of abstractions might be suitable in order to make the solution object- oriented? There are many ways of defining an object, and the conventions used vary according to the particular PL and upon the application at hand and one’s individual judgement.

17 Questioning OOP Object orientation by classification - employee -> administrative employee (isa) Object orientation by composition - car ->engine -> body (hasa) How relevant is object orientation by classification? Is object orientation by composition more useful? Is inheritance really useful? Can inheritance lead to problems?


Download ppt "OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really."

Similar presentations


Ads by Google