DOC PREVIEW
LETU COSC 2103 - Object Based Programming

This preview shows page 1-2-23-24 out of 24 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 24 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 24 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 24 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 24 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 24 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Object Based ProgrammingContrastFind the Objects … the VerbsAbstract Data Types (ADTs)Declaring ClassesConstructorsUsing ClassesClass ScopeControlling Access to MembersUsing the this ReferenceUsing Overloaded ConstructorsUsing Set and Get MethodsCompositionEnumerations – enum typesSlide 15Slide 16Garbage Collectionstatic Class MembersSlide 19Slide 20static ImportFinal Instance VariablesSoftware ReusabilityData Abstraction & EncapsulationObject Based ProgrammingChapter 82Contrast•____________________ Languages–Action oriented–Concentrate on writing ________________–Data supports the actions•Object Oriented Languages–Concentrate on creating reference types–Look for ____________ which indicate classes•Fields are data members•Methods support manipulation of the objects3Find the Objects … the VerbsIn this game, what are nouns that are potential classes?In this game, what are nouns that are potential classes?What are verbs that represent things that the objects do?What are verbs that represent things that the objects do?4Abstract Data Types (ADTs)•Classes in Java make creation of ADTs easier–Implementation details ____________ from users of the class–Client code not dependent on ________________•Example of a class–Figure 8.1 –Time class – keeps track of time in 24 hour format5Declaring Classes•Usually data fields are specified as _____ _____•______________ are declared as public•Any class member (data or method) which does not need to be accessed outside the class should be private•It ____________________________ which comes first, data fields or methods–The author prefers data fields first6Constructors•Methods which have the same name as the _____________________•Included in a class to ensure that instance variables contain __________________ when objects are created•The constructor is called when a class object is created with the _____ ______ _______•Note:–Do not have the constructor return a _________7Using Classes•View Figure 8.2•Note–Creation of a time object with new–Call of the constructor–Use of public functions to ____________ the private data values–Use of toString functions–Use of DecimalFormat class•Advantages of classes–Simplifies client __________________ of classes–Reduces number of _______________________8Class Scope•Variables and methods belong to the class's scope•_________________ the class's scope–All class members are available, accessible•Outside the class's scope–Client code that uses the class–Only _____________ members are available, accessible•Access modifiers public and private control this availability9Controlling Access to Members•The following would not be allowed – why?•The data members are ___________.public class TimeTest2 { public static void main( String args[] ) { Time1 t = new Time1(); t.hour = 7; }}public class TimeTest2 { public static void main( String args[] ) { Time1 t = new Time1(); t.hour = 7; }}10Using the this Reference•Every object can access a reference to ______–Use the keyword this•If a method has a ________ variable with same name as _________ variable, use the th is to access the class variable•Explicit use of this can increase program _____________ for human readers•Note example, Figure 8.411Using Overloaded Constructors•________________ constructors for the same class are allowed•The _____________ of the constructors must be different–Different numbers and/or types of parameters•See example in Figure 8.5 and 8.612Using S et and Get Methods•Private data fields manipulated only by provided _________________________–Some methods used to _________ the data values–Others used to get the values•Return the value directly•Print the value•Note: this is not the same as making the data values __________________–The set methods are written to ensure valid data values13Composition•A class can have references to __________________________ as members•Example:–An alarm clock class contains a Time object as one of its members–Employee class has Date object as one of its members–See•Date Class, Figure 8.7•Employee Class Figure 8.8•Employee Test program Figure 8.914Enumerations – enum types•Declared with an ___________ declaration•A comma-separated list of enum constants•Declares an enum class with the following restrictions:–enum types are implicitly _____________–enum constants are implicitly ______________–Attempting to create an object of an enum type with new is a compilation error15Enumerations – enum types•enum constants can be used anywhere _____________ can•enum constructor –Like class constructors, can specify ____________ and be overloaded•See example, Figure 8.10•Note test program, Figure 8.1116Enumerations – enum types•static method values–Generated by the __________ for every enum–Returns an array of the enum’s constants in the order in which they were declared•static method _________ of class EnumSet–Takes two parameters, the first and last enum constants in the desired range–Returns an EnumSet containing the constants in that range, ________________–An enhanced _________ statement can iterate over an EnumSet as it can over an array17Garbage Collection•Garbage collection–JVM marks an object for garbage collection when there are no more _________________ to that object–JVM’s garbage collector will retrieve those objects memory so it can be used for other objects–See lines 27 – 32 of Figure 8.13•_________________ method–All classes in Java have the finalize method•Inherited from the Object class–finalize is called by the ____________________ when it performs termination housekeeping–finalize takes no parameters and has no return type _____________18static Class Members•Normally each class object has its own copy of the instance variables•Possible to specify a variable that is __________ by all existing objects of the class–Called a static variable–Also called a __________ variable – class wide information•Also possible to have a static ______________–Can be called even if no object of the class has been instantiated–Use class name, then dot, then static method name•Note examples in Fig. 8.12, test pgm Fig. 8.1319static Class Members•String objects are _________________–String concatenation operations actually result in the creation of a ___________ String object•static


View Full Document

LETU COSC 2103 - Object Based Programming

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Arrays

Arrays

11 pages

Load more
Download Object Based 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 Based 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 Based 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?