SlideShare a Scribd company logo
UML Exercise A "draw" utility program lets users draw several geometric objects on a diagram.  A  geometric  object may  be  a  Circle, Rectangle, Square or Triangle.  A diagram  may  also contain  a text  object. Each geometric object  provides a  draw()  function  to draw itself. They also contain information  about thickness  of  border  lines  (unsigned short),  and shading (filling) (a byte value for color). A Circle holds its center and radius and provides functions to  get and set these values, in addition to a function that returns the area. A Triangle  holds the  coordinates of  the  three  sides  and  provides functions to get and set these values. A Rectangle  and  Square  also hold the coordinates of their four sides and provide functions to get and set these values. A  Text Object  has a string, coordinates of the first character, color of the text,  its font name,  point size and  if it  is bold,  italics, underlined  or stricken.  All  these  parameters may  be  modified  and accessed. In addition to the  above geometric objects, the diagram may  also hold sheets. A sheet is an object that appears grayed out on the diagram and may hold a title.  A user may double click on  a  sheet and it opens  a window of its own.  The  difference between a  sheet and a diagram is that a sheet may be contained in a diagram. A sheet may hold any of the geometric objects described above, including other sheets.
Object Copying Let’s first look at some thing simple and fundamental How do we copy an object Consider an example of a Car with an Engine
Venkat’s past recommendation Before reading Bloch’s Effective Java! Writing a Copy Constructor is a bad idea Why? Leads to extensibility issues
Bloch’s Recommendation Cloning comes with its own problems No constructor called when object cloned If a class has final fields, these can’t be given a value within close method! Bloch’s recommendation: "... you are probably better off providing some alternative means of object copying or simply not providing the capability."  He goes on to say  "A fine approach to object copying is to provide a copy constructor."   I agree with the part “simply not providing the capability” But providing a copy constructor has problems mentioned earlier?  What’s the solution? Further Reading: [1]
A combined approach Implement the clone method but not the way it is generally done in Java Write a protected copy constructor From the clone method, invoke the protected copy constructor Further Reading: [2]
References 1. Effective Java, Joshua Bloch 2. “Why copying an object is a terrible thing to do?” (downloadable from http:// www.AgileDeveloper.com/download.aspx )

More Related Content

PDF
Combinatorial optimization CO-6
PPTX
Introduction to image processing and pattern recognition
PPT
Math Editing and display using Microsoft Office 2007 System
PPTX
Parcel Lot Division with cGAN
PPTX
Group Presentation Final Math
PPTX
[Seminar] 200508 hyunwook lee
PDF
Me 443 1 what is mathematica Erdi Karaçal Mechanical Engineer University of...
Combinatorial optimization CO-6
Introduction to image processing and pattern recognition
Math Editing and display using Microsoft Office 2007 System
Parcel Lot Division with cGAN
Group Presentation Final Math
[Seminar] 200508 hyunwook lee
Me 443 1 what is mathematica Erdi Karaçal Mechanical Engineer University of...

Similar to Session02 Part Ii (20)

PDF
Basics of CAD software for oil and gas engineers.pdf
PDF
UML Overview and Introduction functions.pdf
PPT
Fundamentals of Software Engineering
PPTX
COMP111-Week-1_138439.pptx
PPTX
OOP in C# Classes and Objects.
PPTX
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
PPT
Uml lecture
PPTX
UNIT-3 Design Using UML_Design_of_UML.pptx
PDF
Uml basics
PDF
Uml basics
PPTX
UNIT-3 Design Using UML (1).pptx
PPT
CSCI-383 Lecture 3-4: Abstraction
PDF
Object oriented modelling
PDF
Please make the complete program, Distinguish between header files a.pdf
PDF
CSCI 383 Lecture 3 and 4: Abstraction
PPTX
UML Design.pptx
PDF
Read carefully and follow exactly Java You are to write a Breakou.pdf
DOCX
Ooad unit 1
PPTX
Ooad static diagram
PPTX
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Basics of CAD software for oil and gas engineers.pdf
UML Overview and Introduction functions.pdf
Fundamentals of Software Engineering
COMP111-Week-1_138439.pptx
OOP in C# Classes and Objects.
UML_Lecture.pptxnd bfdjjrnekdddkeeeenekejneje
Uml lecture
UNIT-3 Design Using UML_Design_of_UML.pptx
Uml basics
Uml basics
UNIT-3 Design Using UML (1).pptx
CSCI-383 Lecture 3-4: Abstraction
Object oriented modelling
Please make the complete program, Distinguish between header files a.pdf
CSCI 383 Lecture 3 and 4: Abstraction
UML Design.pptx
Read carefully and follow exactly Java You are to write a Breakou.pdf
Ooad unit 1
Ooad static diagram
Intro To C++ - Class 05 - Introduction To Classes, Objects, & Strings
Ad

More from Dang Tuan (20)

PDF
Javascript for php developer
PDF
Power your web skills
PDF
Ube Databases
PPT
Chapter1
PPT
Chapter9
PPT
Chapter3
PPT
Chapter7
PPT
Chapter5
PPT
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
PPT
Ooad Uml
PPT
M02 Uml Overview
PPT
UML for OOAD
PPT
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
PPT
Introduction to Modeling Java and UML
PPT
Information Systems Analysis and Design Overview of OOAD, UML, and RUP
PPT
Ooad Overview
PPT
M03 2 Behavioral Diagrams
PPT
M05 Metamodel
PPT
M04 Design Patterns
PPT
M03 1 Structuraldiagrams
Javascript for php developer
Power your web skills
Ube Databases
Chapter1
Chapter9
Chapter3
Chapter7
Chapter5
PHÂN TÍCH VÀ THIẾT KẾ HỆ THỐNG DÙNG UML
Ooad Uml
M02 Uml Overview
UML for OOAD
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
Introduction to Modeling Java and UML
Information Systems Analysis and Design Overview of OOAD, UML, and RUP
Ooad Overview
M03 2 Behavioral Diagrams
M05 Metamodel
M04 Design Patterns
M03 1 Structuraldiagrams
Ad

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
PPT
Teaching material agriculture food technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Spectroscopy.pptx food analysis technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.
Teaching material agriculture food technology
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation_ Review paper, used for researhc scholars
sap open course for s4hana steps from ECC to s4
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectroscopy.pptx food analysis technology
The AUB Centre for AI in Media Proposal.docx
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
Spectral efficient network and resource selection model in 5G networks

Session02 Part Ii

  • 1. UML Exercise A "draw" utility program lets users draw several geometric objects on a diagram. A geometric object may be a Circle, Rectangle, Square or Triangle. A diagram may also contain a text object. Each geometric object provides a draw() function to draw itself. They also contain information about thickness of border lines (unsigned short), and shading (filling) (a byte value for color). A Circle holds its center and radius and provides functions to get and set these values, in addition to a function that returns the area. A Triangle holds the coordinates of the three sides and provides functions to get and set these values. A Rectangle and Square also hold the coordinates of their four sides and provide functions to get and set these values. A Text Object has a string, coordinates of the first character, color of the text, its font name, point size and if it is bold, italics, underlined or stricken. All these parameters may be modified and accessed. In addition to the above geometric objects, the diagram may also hold sheets. A sheet is an object that appears grayed out on the diagram and may hold a title. A user may double click on a sheet and it opens a window of its own. The difference between a sheet and a diagram is that a sheet may be contained in a diagram. A sheet may hold any of the geometric objects described above, including other sheets.
  • 2. Object Copying Let’s first look at some thing simple and fundamental How do we copy an object Consider an example of a Car with an Engine
  • 3. Venkat’s past recommendation Before reading Bloch’s Effective Java! Writing a Copy Constructor is a bad idea Why? Leads to extensibility issues
  • 4. Bloch’s Recommendation Cloning comes with its own problems No constructor called when object cloned If a class has final fields, these can’t be given a value within close method! Bloch’s recommendation: "... you are probably better off providing some alternative means of object copying or simply not providing the capability." He goes on to say "A fine approach to object copying is to provide a copy constructor." I agree with the part “simply not providing the capability” But providing a copy constructor has problems mentioned earlier? What’s the solution? Further Reading: [1]
  • 5. A combined approach Implement the clone method but not the way it is generally done in Java Write a protected copy constructor From the clone method, invoke the protected copy constructor Further Reading: [2]
  • 6. References 1. Effective Java, Joshua Bloch 2. “Why copying an object is a terrible thing to do?” (downloadable from http:// www.AgileDeveloper.com/download.aspx )