DOC PREVIEW
U of I CS 421 - Object-Oriented Languages

This preview shows page 1-2-3-18-19-37-38-39 out of 39 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 39 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

OutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesCS421 Lecture 19: Object-Oriented Languages1Mark [email protected] of Illinois at Urbana-ChampaignJuly 24, 20061Based on slides by Mattox Beckman, as updated by Vikram Adve, GulAgha, and Elsa GunterMark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesMark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesObjectivesBy the end of this lecture, you should◮be familiar with the core concepts of object- orientedlanguages◮understand different design decisions made in designing OOlanguages◮understand different methods of typing object- orientedlanguages, including some of the theory behind why this ischallenging◮know the difference between object (or prototype) languagesand class-based, object-oriented languagesMark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesObject-Oriented LanguagesObject-oriented (OO) languages are those based around theconcepts of:◮The class, an abstract enti ty which specifies data andfunctionality rel ated to that data; and◮the object, an instance of a particular class which actuallycontains the specified data and provides something for thespecified functionality to work on.OO languages can be seen as an extension of ADT mechanisms,but with some additional features.Mark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesOO Languages – Core ConceptsFor a language to be an OO language it generally must support thefollowing three concepts:◮Encapsulation: The language should have some method forcontaining and potentially hiding parts of definitions, similarto those present in module systems and used with ADTs;◮Inheritance: It should be possible for one cl ass to inheritfunctionality from one or more other classes, allowing forreuse of existing functionality;◮Polymorphism: Different objects should be able to respondto the same request in different ways; essentially, we should beable to ask objects to “do something”, allowing them to figureout how to do it.Different languages approach these three points in different ways.Mark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesEncapsulationEncapsulation is part of what makes objects objects, instead ofjust ADTs (caveat: some ADTs, such as in Euclid, have similarfunctionality, with ADTs as types):◮Each object contains data associated to it;◮each object contains functionality that knows how to operateover that data;◮objects ask other objects to do things for them by callingmethods or sending messages.Mark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesBasic EncapsulationAt it s most basic, encapsulation just allows data members (alsoproperties or fields) and function members (methods) to bedeclared as part of a class.◮Note that this does not give us any data hiding;◮this also doesn’t give us any “internal” functionality – anyobject could call a method on any other objectMark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesEncapsulation OptionsA range of choices about how to handle encapsulation is availablein current OO languages:◮are fie lds visible outside a class?◮can objects of a class see inside other objects of the sameclass?◮is it possible to set different levels of visibility on fields andmethods?◮do the visibility mechanisms interact with the inheritancemechanism?◮do the visibility mechanisms interact with othernaming/grouping mechanisms?Mark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesInheritance OverviewSingle InheritanceMultiple InheritanceOther Inheritance ModelsInheritance, Overrides, and EncapsulationInheritanceIn OO languages, inheritance allows a class to reuse functionalityfrom (usually) another class, without having to rewrite orcopy/paste the code.◮The parent, base, or super class is the class being inheritedfrom.◮The child, derived, or sub class is the class doing theinheriting.◮The child class can reuse the functionality from the parentclass, including functionality the parent got from its parent,etc.Mark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesInheritance OverviewSingle InheritanceMultiple InheritanceOther Inheritance ModelsInheritance, Overrides, and EncapsulationTypes of Inheritance◮Some languages only allow a class to inherit from one otherclass – this is single inheritance.◮Some languages allow a class to inherit from multiple classes,which is multiple inheritance.◮An alternate model of inheritance allows functionality to bepulled out into distinct units which can then be used to formnew classes. These units of reuse are called mixins.◮Mixins arguably introduce some complications, which traitsare i ntended to solve.Mark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesInheritance OverviewSingle InheritanceMultiple InheritanceOther Inheritance ModelsInheritance, Overrides, and EncapsulationSingle InheritanceSingle-inheritance languages only allow a class to inherit from oneother class.◮Examples include Java, C#, and Smalltalk◮Generally includes a designated base class from which allother classes inherit (Object in Java)◮Semantically cleaner◮Easier to predict behavior◮Easier to translate/compile◮Cannot model some situationsMark Hills CS421 Lecture 19: Object-Oriented LanguagesOutlineEncapsulationInheritancePolymorphismTyping and Object-OrientationObject-Based LanguagesInheritance OverviewSingle


View Full Document

U of I CS 421 - Object-Oriented Languages

Documents in this Course
Lecture 2

Lecture 2

12 pages

Exams

Exams

20 pages

Lecture

Lecture

32 pages

Lecture

Lecture

21 pages

Lecture

Lecture

15 pages

Lecture

Lecture

4 pages

Lecture

Lecture

68 pages

Lecture

Lecture

68 pages

Lecture

Lecture

84 pages

s

s

32 pages

Parsing

Parsing

52 pages

Lecture 2

Lecture 2

45 pages

Midterm

Midterm

13 pages

LECTURE

LECTURE

10 pages

Lecture

Lecture

5 pages

Lecture

Lecture

39 pages

Load more
Download Object-Oriented Languages
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Object-Oriented Languages and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Object-Oriented Languages 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?