Presentation on theme: "1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology."— Presentation transcript:
1 Introduction to Object Orientation (OO) & Related Terminology zIn a non-programming specific way, orient ourselves to the principles and related terminology to OO development zIdentify KEY OO Terms
2 zGOALS... zTO understand prevailing methodology & related principles zTo match relevant programming terminology to OO principles
3 zDevelopment in VB: zGiven a problem zStarted Coding zAsked Questions on What you were Supposed to do !!! zMade Major changes to your programs zSome testing...
4 z...Development in VB: zAsked for me to Grade it zWhite Elephant z(Major) modifications zFinally Done !!!
5 z...Development in VB: zThen, the Next project followed the same paradigm with little reuse of prior code
6 zVB Terms: zVariables zEvents zSubroutines
7 zDevelopment in Java: zRemember how I required you to code the File I/O projects ? zStructures zSeparate code module routines to open, read and write File I/O zDisplay data on a form To/From Structures
8 zDevelopment in Java: zIn General, we separated the Display (GUI) from the Data Gathering from the Data Modifications
9 zDevelopment in Java: zFurthermore, In the Code Modules we attempted to Separate the processing from the Displaying as the Code Modules should make NO reference to the controls on the form (textboxes, labels, etc)
10 zDevelopment in Java: zIn theory, we could have taken your Code module and used it for other programs without : xKnowing or Caring how the data was processed, modified or Displayed
11 zNow in Java we WILL… zGiven a problem zUNDERSTAND the problem zBreak the problem up into manageable pieces
12 zNow in Java we WILL… zIdentify the relevant functions that each piece needs to perform zCreate the variables necessary to maintain the STATE of each piece
13 zNow in Java we WILL… zIdentify how each piece will communicate zDevelop the main program driver that will control the process (except for event driven Projects)
14 zNow in Java we WILL… zTest, debug and modify zAsked for me to Grade it zDone !!!
15 zJava Terms: zAttributes zEvents zMethods
16 zIn our File I/O project, we can write the following methods: zOpen a file zProcess a file zUpdate a file zClose a file
17 zIn our File I/O project, we can write the following methods: zRead data from the user (console) zSend data to the user (console) zThese methods will be able to be reused for any other project that requires Retrieving / Sending data
18 zOld School Development: zSet up separate phone lines FOR EACH person you wish to talk to zWasteful zRepeats 99 percent of the same functionality
19 zOO Development: zDevelop classes that handle the different parts of a GENERIC phone communication process (identify who to call, place a call, engage in conversation, end the call)
20 zOO Development: zSet up 1 general use phone line that can handle multiple INSTANCES of phone calls to anyone who has a phone zCreates useful and extensible components
21 zOO Development: zReuses a generic communication protocol and instantiates it with a STATE based on the person you wish to talk to (phone number, etc)
22 zTPS:PERSON zThink of a generic person blueprint and answer the following questions:
23 zWhat ATTRIBUTES (properties) apply to the Person Blueprint ?
24 zWhat ATTRIBUTES (properties) apply to the Person Blueprint ? Hair Voice Size Skin Tone Gender Race SSN AGE
25 zWhat BEHAVIORS (methods) apply to the Person Blueprint ?
26 zWhat BEHAVIORS (methods) apply to the Person Blueprint ? Change Hair Color Change Size Change Gender
27 zWhat if we disallow or encapsulate the ability for ANY user of the Person Blueprint from altering hair color ?
28 zHow can we use this blueprint to create other types of Persons ? Teacher Person Policeman Person Male Person Female Person
29 zHow does the use of the Generic Person Blueprint assist us in creating these instances of the generic Person ?
30 zWhat about Attributes and Behaviors that are different in these instances ?
31 zAnswers the SAME questions for: zA Generic Car Blueprint
32 zAnswers the SAME questions for: zA Salary Calculation Application
34 zWe will use the LOAN class analogy zThere can be many types of loans: ycar ymortgage ystudent
35 OOP in a Nutshell: zA program models a world of interacting objects zObjects create other objects and send messages to each other (in Java, call each others methods) z Each object belongs to a class; a class defines properties of its objects z A class implements an ADT; the data type of an object is its class z Programmers write classes (and reuse existing classes)
36 Abstraction... relevant to the given project (with an eye to future reuse in similar projects). Abstraction means ignoring irrelevant features, properties, or functions and emphasizing the relevant ones... Relevant to what?
37 zExample: In identifying the relevant elements in building a generic blueprint for handling various loans, you can ignore adding functionality that calculates the square of all natural numbers
38 Encapsulation Encapsulation means that all data members (fields) of a class are declared private. Some methods may be private, too. The class interacts with other classes (called the clients of this class) only through the classs constructors and public methods. Constructors and public methods of a class serve as the interface to classs clients.
39 Encapsulation The Hiding or Shielding of some of the properties and or behaviors of the class from users of the class
40 Encapsulation ensures that structural changes remain local zChanges in the code create software maintenance problems zUsually, the structure of a class (as defined by its fields) changes more often than the classs constructors and methods zEncapsulation ensures that when fields change, no changes are needed in other classes (a principle known as locality)
41 z Example: In building the loan class, you would hide an attribute that holds the Prime Interest Rate as well as any intermediate calculation attributes
42 z Example: Encapsulation allows the class to restrict how the attributes can be modified
43 True or False? Abstraction and encapsulation are helpful for the following: Team development ________ Reusable software ________ GUI programming ________ Easier program maintenance ________
44 Answer: Team development ________ Reusable software ________ GUI programming ________ Easier program maintenance ________ T T T (True if you are working on system packages, such as Swing) F
45 Inheritance A class can extend another class, inheriting all its data members and methods while redefining some of them and/or adding its own. Inheritance represents the is a relationship between data types. For example: a HomeLoan is a ;loan.
46 Inheritance The Use of a BASE or Blueprint class that contains the common properties and behaviors to create a subset of the class
47 zExample: With our loan class, the calculation of the Interest Rate may be the same Regardless of the type of loan. So, you could design the Loan class so that...
48 zExample: … It does the calculation and all of the loan types can inherit and USE that Calculation.
49 True or False? Inheritance is helpful for the following: Team development ________ Reusable software ________ GUI programming ________ Easier program maintenance ________
50 Answer: Team development ________ Reusable software ________ GUI programming ________ Easier program maintenance ________ F T ??? T
51 Polymorphism Polymorphism ensures that the appropriate method is called for an object of a specific type when the object is disguised as a more general type. Good news: polymorphism is already supported in Java all you have to do is use it properly.
52 Polymorphism The Use of a base class to serve as an interface to the use or implementation of ANY Derived Classes
53 Called Dymanic Method Binding or Late Binding You can create a generic blueprint class that performs methods common to any class that inherits from it. You only need to create a placeholder of the generic class and then fill it in as needed.
54 Example: With the car loan, we create the generic Loan class. ThisClass performs the common methods and holds common attribute STATE
55 Example: We can create a placeholder of the Loan class and then fill it with the studentloan inherited version of the Loan class And it will, by default, contain the same public methods as the Generic Loan class
56 zTPS: zTake one of the examples of Person, Car or Salary Calculation to create a SUPER BLUEPRINT that maintains attributes and behaviors that ARE COMMON regardless of the TYPE of Person, Car or Type of Salary being calculated (inheritance)
57 zTPS: zUsing the previous example, what attributes or behaviors can be Hidden ?
58 zOther Characteristics of OO zDivide and Conquer Principle zInterface Principle zInformation Hiding Principle zGenerality Principle