Software Engineering I Sept. 4, 2013 Review of Object Oriented Programming -Using Java because you should be familiar with it Object Oriented Systems use abstraction to make SW less complex Abstraction (partial definition) - expressing the qualities of objects and being able to visualize them without needing a complete definition. Abstraction helps you to avoid worrying about some of the details of programming and helps you to focus on the real problem. Object oriented programming uses both procedural and data abstraction. Procedural abstraction - abstracting functions/methods/routines - Pass in parameters and get output - Don't worry about how it works (black box) Example - a summation function int sum(int [] intArray); We don't need to look at the inside of the function to understand how it should work. Procedural abstraction is fine by itself for functionality that doesn't need to be associated with an object (e.g. static methods). Data abstraction Records or structures were the first types of data abstraction. This is grouping data together. Example: public class PlayingCard { public String suit; public int faceValue; } Object Oriented Paradigm Perform computing in the context of objects Objects are instances of programming constructs (in our case classes), which may include both data and procedural abstractions to operate upon the objects Procedural vs. Object Oriented Programming OOP +------------------+ | Account | +------------------+ | Credit() | +------------------+ | Debit() | +------------------+ ^ / \ --- | +----+------+ | | +---------+-----+ +-+-------------+ | CheckingAcct | | SavingsAcct | +---------------+ +---------------+ | CompInterest()| | CompInterest()| | ComputeFees() | | ComputeFees() | +---------------+ +---------------+ Procedural +----+ |main| +----+ | +--------------------------------------+ | Perform Transaction | +--------------------------------------+ | | | | +------+ +-----+ +--------------+ +--------------+ |Credit| |Debit| |CompInterest | |CompFees | +------+ +-----+ | if checking | |if checking...| | elseif saving| +--------------+ +--------------+ Objects are instances of a class Groups of data in a structured format with functionality specific to that structure. An object may have both attributes and specific functionality (methods). Attributes describe the object's current state and characterize the object. Functionality shows how the object can react to change in state UML Example of Objects (not classes) +--------------------+ +--------------------------+ | SavingsAcct 13264: | | Jane: | | ------------------ | | ----- | +--------------------+ +--------------------------+ | balance = 2316.22 | | dob = 6/3/1978 | | opened = 4/5/2012 | | addr = "800 Univ. Dr" | | | | position = Manager | +--------------------+ +--------------------------+ Object Oriented Analysis - Decide which objects to save and which are important - Determine structure, relationships, and behavior of objects - Can figure out physical representation later Classes - units of data abstraction that define the structure of instances All objects with the same properties and behavior are instances of a class Example - an employee like Jane Methods - behaviors of objects When should you define a class? When you see something that can be clearly defined as a single member of a class and can be reused Naming classes Start with a capital letter, All words in class name start with a capital letter. Typically name after a real world object. Examples: Doctor, Hospital, Employee, PartTimeEmployee Creating classes can be an art. Don't be too general or specific. Instance variables - properties of classes - contain class data Different kinds of instance variables exist attributes - about the class (e.g. a name for an employee) associations - relationships of one class to another (supervisor to employee)