Unformatted text preview:

Object-Oriented Programming (Section 10.1-10.2)Data Abstraction and Object OrientationHistorical Development of AbstractionFundamental Concepts in OOPEncapsulationEncapsulation Classes, Objects and MethodsEncapsulation Modules and ClassesClasses and Encapsulation Two ViewsVisibility RulesAccess RestrictionsC++ List ExampleC++ ExampleSlide 13Slide 14Ada 95Slide 16Slide 1711Object-Oriented ProgrammingObject-Oriented Programming(Section 10.1-10.2)(Section 10.1-10.2)CSCI 431 Programming LanguagesCSCI 431 Programming LanguagesFall 2003Fall 2003A compilation of material developed by Felix A compilation of material developed by Felix Hernandez-Campos and Michael ScottHernandez-Campos and Michael Scott22Data Abstraction and Object Data Abstraction and Object OrientationOrientation•Control or Control or processprocess abstraction is a very old idea abstraction is a very old idea (subroutines!), though few languages provide it in a (subroutines!), though few languages provide it in a truly general form (Scheme comes close).truly general form (Scheme comes close).•Data abstraction is somewhat newer, though its roots Data abstraction is somewhat newer, though its roots can be found in Simula67.can be found in Simula67.•An Abstract Data Type is one that is defined (from An Abstract Data Type is one that is defined (from the user’s point of view) in terms of the operations the user’s point of view) in terms of the operations that it supports (i.e. that can be performed upon it) that it supports (i.e. that can be performed upon it) rather than in terms of its structure or rather than in terms of its structure or implementation.implementation.33Historical Development of Historical Development of AbstractionAbstraction•We’ve talked about data abstraction previously. We’ve talked about data abstraction previously. Recall the historical development of data abstraction Recall the historical development of data abstraction mechanisms:mechanisms:global set of variablesglobal set of variablesBasicBasiclocalslocalsFortranFortranstaticsstaticsFortran, Algol 60, CFortran, Algol 60, CmodulesmodulesModula-2, Ada 83Modula-2, Ada 83module typesmodule typesEuclidEuclidobjectsobjectsSmalltalk, C++, Eiffel, Java,Smalltalk, C++, Eiffel, Java, Oberon, Modula-3, Ada 95Oberon, Modula-3, Ada 9544Fundamental Concepts in OOPFundamental Concepts in OOP•EncapsulationEncapsulation–Data AbstractionData Abstraction–Information hidingInformation hiding•InheritanceInheritance–Code reusabilityCode reusability–Is-a vs. has-a relationshipsIs-a vs. has-a relationships•PolymorphismPolymorphism–Dynamic method bindingDynamic method binding55EncapsulationEncapsulation•Data abstractionData abstraction allow programmers to hide data allow programmers to hide data representation details behind a (comparatively) representation details behind a (comparatively) simple set of operations (an simple set of operations (an interfaceinterface))•What the benefits of data abstraction?What the benefits of data abstraction?–Reduces Reduces conceptual loadconceptual load »Programmers need to knows less about the rest of the programProgrammers need to knows less about the rest of the program–Provides Provides fault containmentfault containment»Bugs are located in independent componentsBugs are located in independent components–Provides a significant degree of Provides a significant degree of independenceindependence of program of program componentscomponents»Separate the roles of different programmerSeparate the roles of different programmerSoftware Software EngineeringEngineeringGoalsGoals66EncapsulationEncapsulationClasses, Objects and MethodsClasses, Objects and Methods•The unit of encapsulation in an OO PL is a The unit of encapsulation in an OO PL is a classclass–An abstract data typeAn abstract data type»The set of values is the set of The set of values is the set of objectsobjects (or (or instancesinstances))•Objects can have aObjects can have a–Set of Set of instanceinstance attributes attributes ((has-a relationshiphas-a relationship))–Set of Set of instanceinstance methodsmethods•Classes can have aClasses can have a–Set of Set of class attributesclass attributes–Set of Set of class methodsclass methodsMethod calls are Method calls are known as known as messagesmessages•The entire set of methods of an object is known as the The entire set of methods of an object is known as the message protocolmessage protocol or the or the message interface message interface of the objectof the object77EncapsulationEncapsulationModules and ClassesModules and Classes•The basic unit of OO, the class, is a The basic unit of OO, the class, is a unit of scopeunit of scope–This idea appeared in module-based languages in the mid-This idea appeared in module-based languages in the mid-70s70s»E.g.E.g. Clu, Modula, Euclid Clu, Modula, Euclid•Rules of scope enforce data hidingRules of scope enforce data hiding–Names have to be Names have to be exportedexported in order to be accessible by in order to be accessible by other modulesother modules88Classes and EncapsulationClasses and EncapsulationTwo ViewsTwo Views•Module-as-typeModule-as-type–A module is an abstract data typeA module is an abstract data type–Standardized constructor and destructor syntaxStandardized constructor and destructor syntax–Object-oriented design is applied everywhereObject-oriented design is applied everywhere–E.g. Java, Smalltalk, Eiffel, C++, PythonE.g. Java, Smalltalk, Eiffel, C++, Python•Module-as-managerModule-as-manager–A module exports an abstract data typeA module exports an abstract data type–Create and destroy operationsCreate and destroy operations–Object-oriented design is optional (OO as an extension)Object-oriented design is optional (OO as an extension)–E.g. Ada 95, Modula-3, Oberon, CLOS, PerlE.g. Ada 95, Modula-3, Oberon, CLOS, Perl99Visibility RulesVisibility Rules•Public and Private parts of an object Public and Private parts of an object declaration/definition.declaration/definition.•2 reasons to put things in the declaration2 reasons to put things in the declaration– so programmers can get at themso programmers can get at them– so the compiler can understand themso the compiler can understand them•At the very least the compiler needs to know the size At the very least the compiler needs to know the size of an object, even though the programmer isn't of an


View Full Document

UNCA CSCI 431 - Object-Oriented Programming

Download Object-Oriented Programming
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 Programming 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 Programming 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?