Docsity

Object Oriented Methodology - OOM - Part 5, Study notes of Object Oriented Programming

Partial preview of the text

Download Object Oriented Methodology - OOM - Part 5 and more Study notes Object Oriented Programming in PDF only on Docsity!

1

Object Oriented Methodology Object Oriented Methodology

2

OOM OOM

 AboutAbout OOP :OOP :

 (^) Procedure Oriented Vs. Object Oriented

 OOP ConceptsOOP Concepts

 (^) Objects & Classes  (^) Elements of the Object Model  (^) Problem solving in OOP methodology

 Implementation issuesImplementation issues

 (^) OOP implementations: Java Vs. C++ etc.

 (^) Working of a Java Program

  • (^) Compiler-Interpreter & Java Programming  (^) Java Functionality: Servlets & Applets?
  • (^) Platform independent : JVM
  • (^) Console Operation Vs. IDE : JDK Vs. NetBeans  (^) Tools needed: JDK , IDE  (^) Writing Java Class  (^) Adding Methods to a Class

 Object Oriented ModelingObject Oriented Modeling

Procedure Oriented Vs. Object Oriented Procedure Oriented Vs. Object Oriented

 In the early days of programming, programs were designed

using flowcharts and a sort of topdown design.

 With this type of design, a large problem is solved by

breaking it down into smaller tasks.

 For each of the smaller tasks, a procedure is written.

 One main procedure was written to start the process and

subsequently flow through to the solution, invoking the

desired procedures along the way.

 Procedural programming involves writing a procedure that

performs a specific task.

 Any data that the procedure needs to use is passed in to the

procedure via its parameters.parameters

 The procedure can view and alter the data passed in and

optionally return a value back to whoever called the procedure.

4

OOPS vs. Procedure Oriented OOPS vs. Procedure Oriented

 We can think of procedural programming as writing a

procedure for the verbs in the problem domain, such as

paying an employee paying an employee or computing taxescomputing taxes.

 You can think of objectoriented programming as writing a

class for each of the nouns in the problem domain.

 Granted, this may be oversimplifying OOP, but this

conceptually explain this important difference between OOP

and procedural programming.

 OOP takes an entirely different approach to developing

computer applications. Instead of designing a program around

the tasks that are to be solved, a program is designed around

the objects in the problem domain.

5

Problem Solving in Procedure Oriented Problem Solving in Procedure Oriented

 (^) As your employee program evolves, you will certainly findemployee program

yourself adding and changing procedureadding and changing procedure s so that everything works successfully.

 (^) For example, as you start writing the computePay() procedurecomputePay() procedure, you might realize that there are two different types of employees (at least in terms of how they get paid): hourly employees and salaried employees.

 (^) In this situation, you might decide to write two computePay() procedures, one for hourly employees and a different one for salaried employees.

 (^) Writing a procedure to solve a specific task is a fundamental

programming concept used in both procedural languages and in objectoriented programming.

 (^) As you design and write Java programs, procedures will be an

essential element for solving the problem at hand

7

Different Programming Paradigms Different Programming Paradigms

 (^) Functional/procedural programming:Functional/procedural programming:

program is a list of instructions to the computer .

 (^) Objectoriented programmingObjectoriented programming

program is composed of a collection : objects that communicate with each other

 (^) OOPS with JavaOOPS with Java

In Java, procedures are referred to as methods.

Methods in Java appear within a class. Procedures in a procedural language typically appear at a global level so that they can be invoked from anywhere.

Objects & Classes Objects & Classes

 Favorite analogy when explaining classes and objects is to

compare blueprints of houseblueprints of house to a class.

 A blueprint of a house tells you what the house will look like

when it is built, but it is clearly not a house—just a

description of one.

 When a contractor follows the blueprints and actually builds

an instance of a househouse that house is an object.

 How many houses can you build from a set of blueprints?

As many as you want.As many as you want.

 How many instances of a class (that is, objects) can you

create?

 As many as you want.As many as you want.

10

OOP : Why & How? OOP : Why & How?

11

Object-oriented programming (OOP) is a programming

paradigm that uses "objects" and their interactions to

design applications and computer programs. It is based

on several techniques.

Object oriented programming roots reach all the way

back to the 1960s. As researchers studied how softwarehow software

quality could be maintainedquality could be maintained****.

Object-oriented programming was deployed in part as an

attempt to address this problem by strongly emphasizingstrongly emphasizing

discrete units of programming logic and re-usabilitydiscrete units of programming logic re-usability in

software.

OOM OOM

13

 (^) With the dominance of OOP, Objectoriented modeling

has become the defacto standarddefacto standard in the early phases of a software development process during the last decade..

 (^) The most single important abilityability in object oriented

analysis and design is;

 (^) to skillfully assign responsibilities to software components.

OOPS advantages OOPS advantages

 (^) Bundling code into individual software objects has advantages;

  1. Modularity: The source code for an object can be written and maintained independently of the source code for other objects. Once created, an object can be easily passed around inside the system.

  2. Informationhiding : By interacting only with an object's methods, the details of its internal implementation remain hidden from the outside world.

  3. Code reuse : If an object already exists (perhaps written by another software developer), you can use that object in your program. This allows specialists to implement / test / debug complex, taskspecific objects , which you can then trust to run in your own code.

  4. Pluggability and debugging ease: If a particular object turns out to be problematic, you can simply remove it from your application and plug in a different object as its replacement. This is analogous to fixing mechanical problems in the real world. If a bolt breaks, you replace it, not the entire machine.

14

Problem Solving in Object Oriented Problem Solving in Object Oriented

 (^) As your problem evolves, you have to certainly identifyproblem

objects so that OOPS works successfully.

 (^) After you have determined the objects in the problem, you

write a class to describe the attributes and behaviors of each object.

 (^) The attributes of an object will be what the object “has” such

as a name, address, and so on.

 (^) Each of these attributes will be represented by a field in the

Employee class.

 (^) The behaviors of an object are what the object “doesdoes” (or,

more specifically, what we want the object to do).

 (^) These desired behaviors become methods in the Employee

class.

 (^) Writing a Method inside a Class , to solve a specific task is a

fundamental in objectoriented programming.

16

What Is an Object? What Is an Object?

 Objects are key to understanding objectoriented techno.

 Two important objectoriented terms: object and class.object class.

A A classclass is a description of an object, and anis a description of an object, and an objectobject is anis an

instance of a class. instance of a class.

 Examples of realworld objects:

 (^) your dog, your bicycle, your desk, your television set.your dog, your bicycle, your desk, your television set.

 Realworld objects share two characteristics: They all have

state state and behaviorbehavior.

 Dogs have statestate (name, color, breed, hungry) and behaviorbehavior

(barking, fetching, wagging tail).

 Bicycles also have statestate (current gear, current pedal

cadence, current speed) and behaviorbehavior (changing gear,

changing pedal cadence, applying brakes).

17

27/11/14 04:45 AM Marc Conrad - University of Luton 19

What is an object? What is an object?

 (^) Tangible Things as a car, printer, ...

 (^) Roles as employee, boss, ...

 (^) Incidents as flight, overflow, ...

 (^) Interactions as contract, sale, ...

 (^) Specifications as colour, shape, …

 (^) An object represents an individual, identifiable item, unit, or entity, either real or abstract, with a welldefined role in the problem domain.

 (^) An "object" is anything to which a concept applies.

Objects… Objects…

 (^) Observe the realworld objects that are in your immediate area.

 (^) For each object that you see, ask yourself two questions:

I. "What possible states can this object be in?"

II. "What possible behavior can this object perform?".

 (^) Make sure to write down your observations. As you do, you'll notice

that realworld objects vary in complexity;

 your desktop Lampdesktop Lamp may have only two possible states (on and

off) and two possible behaviors (turn on, turn off),

 but your desktop FM radiodesktop FM radio might have additional statesstates (on, off,

current volume, current station) and behaviorbehavior (turn on, turn off, increase volume, decrease volume, seek, scan, and tune).

 (^) You may also notice that some objects, in turn, will also contain

other objects.

 (^) These realworld observations all translate into the world of object oriented programming.

20