Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design."— Presentation transcript:

1

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

3 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().....

4 Class Blueprint 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).

5 An example of a class & its Objects Class – Dog Objects – Scooby, Snowy, Puppy Attributes – name, color, size, breed.... Methods – run, bark, bite, sit, sleep....

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

7 Dog class From Dog class we can create individual Dog Objects. Puppy object - an instance(example) of Dog class.

8

9 State of an Object Values the attributes of an Object are set to. Could be different for different Objects of the same class.

10

11 We get Objects to do things by calling their methods.

12 Object Orientation Advantages Re-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.

13 Object Orientation Advantages Encapsulation - we can create objects from a class and use its behaviours without needing to know the internal details of how it works.

14 Access Modifier Public Private Default Protected

15 Types of Methods Method that does not return value  Method without parameter  Method with parameter Method that returns value  Method without parameter  Method with parameter

16 Accessing private fields of a class public class Dog{ private String name; private int size; private String color; }

17 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”); }

18 Set methods public 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...... }

19 Get methods public class Dog{ //fields //set methods public 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...... }

20

21 Scope of a variable The 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

22 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 places In a class body as class fields =>classlevel variables As parameter of method or constructor In a method's body or a constructor's body Within a statement block (while or for)

23 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 * breadth return area; }

24 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 inside this method

25 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; }

26

27

28 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); }

29 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(); }


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

Similar presentations


Ads by Google