29

Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Embed Size (px)

DESCRIPTION

Object-Oriented Design(OOD) Most recent software design pattern. Objects: real life objects. Objects have two parts: Attributes: properties of the object.E.g. Name, address Methods: functions(things) an object can do.E.g. prepareFood(), buildHouse().....

Citation preview

Page 1: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design
Page 2: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Software development

For large and complex software use divide and conquer rule.

Software design methods:Structured designObject-Oriented design

Page 3: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Object-Oriented Design(OOD)Most recent software design pattern.

Objects: real life objects.

Objects have two parts:Attributes: properties of the object.E.g. Name,

address......Methods: functions(things) an object can do.E.g.

prepareFood(), buildHouse().....

Page 4: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

ClassBlueprint to create Objects.

What an Object represents is shown by its class.

A class describes what all Objects of a particular type have in common.

A class is a must to create Object(s).

Page 5: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

An example of a class & its ObjectsClass – Dog

Objects – Scooby, Snowy, Puppy

Attributes – name, color, size, breed....

Methods – run, bark, bite, sit, sleep....

Page 6: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Dog class diagram

The Dog class is a template or blueprint for creating dog objects

Page 7: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Dog classFrom Dog class we can create individual Dog Objects.

Puppy object - an instance(example) of Dog class.

Page 8: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design
Page 9: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

State of an ObjectValues the attributes of an Object are set to.

Could be different for different Objects of the same class.

Page 10: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design
Page 11: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

We get Objects to do things by calling their methods.

Page 12: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Object Orientation AdvantagesRe-usability: once we have defined a class, we can

use it over and over again to create many different objects of that type.Someone else can also use this class to create objects

so we can create class library.

when defining new classes we can compose classes from other existing classes to create complex objects.

Page 13: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Object Orientation AdvantagesEncapsulation - we can create objects from a

class and use its behaviours without needing to know the internal details of how it works.

Page 14: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Access ModifierPublic

Private

Default

Protected

Page 15: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Types of MethodsMethod that does not return valueMethod without parameterMethod with parameter

Method that returns valueMethod without parameterMethod with parameter

Page 16: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Accessing private fields of a classpublic class Dog{

private String name;private int size;private String color;

}

Page 17: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

public class Dog{private String name;private int size;private String color;

public Dog(String dName, int dSize, String dColor){

name = dName;size = dSize;color = dColor;

}}

public class Test{public static void main(......){

Dog dObject = new

Dog(“Scooby”,5,”Brown”);}

}

Page 18: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Set methodspublic class Dog{

private String name;private int size;private String color;public void setName(String dName){name = dName;}public void setSize(int dSize){size = dSize;}// do for color..........

}

public class Test{ public static void main(......){

Dog dObject = new Dog();dObject.setName(“Scooby”);dObject.setSize(5);// do for color......

}}

Page 19: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Get methods

public class Dog{//fields//set methodspublic String getName(){

return name;}public int getSize(){

return size;}// do for color........

}

public class Test{ public static void main(......){

Dog dObject = new Dog();System.out.println(“Name: ”+dObject.getName());// do for size.....// do for color......

}}

Page 20: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design
Page 21: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Scope of a variableThe area/part of the program over which a variable can be referenced (i.e. visible).public class Dog{

private String name;…..........public Dog(){

name=”Scooby”;}

}

This variable is visible and can be referenced from anywhere in the class

Page 22: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Scope of a variable (Contd..)You cannot refer to a variable before its

declaration.Inside a class a variable can be declared at

several different placesIn a class body as class fields =>classlevel

variablesAs parameter of method or constructorIn a method's body or a constructor's bodyWithin a statement block (while or for)

Page 23: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Scope of a variable (Contd..)Class-level

public class Calculate{private int length;private int breadth;private int area;…........................public int area(){length = 6;breadth = 2;area=length * breadthreturn area;}}

Page 24: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Scope of a variable (Contd..)As parameter of method or constructor

public class Calculate{public int area(int length, int breadth){return length*breadth;}}

visible only insidethis method

Page 25: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Scope of a variable (Contd..)In a method's body or a constructor's body

public class Calculate{public int area(int length, int breadth){int len = length;int bre = breadth;return len*bre;}}

Page 26: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design
Page 27: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design
Page 28: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Method overloading class MathDemo { public static void areaDemo(double length, double breadth) { double area = length * breadth; System.out.println(“Area of rectangle : ” + area); } public static void areaDemo(double length) { double area = length * length; System.out.println(“Area of square : ” + area); } public static void main(String args[]) { areaDemo(12,15); areaDemo(55); } }

Page 29: Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design

Constructor Overloading class BoxDemo { double volume; public BoxDemo(double length, double breadth, double height) { volume = length * breadth * height; } public BoxDemo(double length) { volume = length * length * length ; } public void volumeDemo() { Systme.out.println(“Volume of box is : “ + volume); }

public static void main(String args[])

{ BoxDemo box1 = new

BoxDemo(5,6,7); box1.volumeDemo();

BoxDemo box2 = new BoxDemo (5);

box2.volumeDemo();}

}