Presentation is loading. Please wait.

Presentation is loading. Please wait.

“OOP” Principles and Philosophy Classes and Objects Inheritance Message Passing Encapsulation Overloading Polymorphism.

Similar presentations


Presentation on theme: "“OOP” Principles and Philosophy Classes and Objects Inheritance Message Passing Encapsulation Overloading Polymorphism."— Presentation transcript:

1 “OOP” Principles and Philosophy Classes and Objects Inheritance Message Passing Encapsulation Overloading Polymorphism

2 Classes and Objects class ComplexShape class SimpleShape ACTIVITY 1

3 Inheritance public class ComplexShape extends SimpleShape { } ACTIVITY 1

4 “ Calling Methods” = “Message Passing” public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setColor(COLOR_BACKGROUND); g2.fillRect(0,0,width,height); for(i=0; i < shapesArray.length;i++) { shapesArray[i].draw(g); } public void draw(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setPaint(color); g2.setStroke(new BasicStroke(2)); if(type == 1) g2.draw(myShape); if(type == 2) g2.fill(myShape); } DisplayCanvas object SimpleShape object “Hey SimpleShape object – draw yourself!”

5 Encapsulation Iterator it = shapeList.iterator(); while(it.hasNext()) { SimpleShape shape = (SimpleShape)it.next(); shapeX = shape.getX(); shapeY = shape.getY();... } Private double x,y; public double getX() { return x; } DisplayCanvas object SimpleShape object shapeX = shape.x; Public double x; ACTIVITY 2

6 Overloading of methods public voiddraw(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setStroke(new BasicStroke(2)); if(type == 1) g2.draw(myShape); if(type == 2) g2.fill(myShape); } public voiddraw(Graphics g) { Graphics2D g2 = (Graphics2D)g; super.draw(g); g2.setStroke(new BasicStroke(10)); g2.setPaint(color2); g2.draw(newBit); } ACTIVITY 1

7 Polymorphism ACTIVITY 4 public Ball(double x, double y, DrawCanvas canvas) { super(x,y,canvas); radius = 10; width = (2*radius); height = (2*radius); super.setWidth(width); … } public Ball(double x, double y, String imageName, DrawCanvas canvas) { super(x,y,canvas); image = loadImage(imageName); } Class Ball Constructor 1 Constructor 2 Ball ball1 = new Ball(10,20,canvas); Ball ball2 = new Ball(12,32,”Bush.jpg”,canvas)

8 Modelling (Carvaggio In Study)

9 UML Software Tools Microsoft Visio DirectUML 1.3.1 (Module Web-page) Fujaba Jude …

10 Dependency ACTIVITY 1 Task 1 UML Objects myShape = new SimpleShape(200,200,100,100,0.6); Class Object

11 Dependency UML Object Diagram ACTIVITY 1 Task 1

12 UML Class Diagram ACTIVITY 1 Task 1 Inheritance

13 UML Sequence Diagram Time


Download ppt "“OOP” Principles and Philosophy Classes and Objects Inheritance Message Passing Encapsulation Overloading Polymorphism."

Similar presentations


Ads by Google