Lecture 16b - name as the package Ie. The physical setup...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Interfaces in UML (CHECK NOTES) An interface is represented like a class stereotyped with <<interface>> Eg: <<interface>> Color _____ +setColor(color: int) : void; + color() : int; A class that implements the interface shows the interface as a small attached circle o You can also show that the class “realizes” the interface with a dashed open arrow o Eg: <<interface>> Color ------------point | OColor Point implements the Color interface A second class that “uses” the interface implemented by the first “depends” on that interface o Dependency is shown with a dashed arrow Packages Are used to group together related classes and interfaces Use the package keyword to indicate that a class or interface belongs to a named package o Must be before the class declaration o Eg: Point.java file: package Gemoetry; public class Point{ ... } Circle.java file: package Geometry; public class Circle{
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
... } o Both classes now belong to the Geometry Package o Normaly, all the class and interface files are put into a subdirectory with the same
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: name as the package Ie. The physical setup must match the logical o Unless declared private, classes, methods, and variables are accessible to all code in the package i.e have package visibility or package scope o To access public classes, methods, and variables in another package, you can: Use the fully qualified name Eg: Geometry.Point myPoint; Import part or all of a package, and use the simple name eg: import Geometry.*; ... Point myPoint; o The use of packages solves most naming conflicts A package creates a unique namespace Two or more classes can have the same name if they belong to different packages i.e. are in different namespaces java.lang.Point and java.util.Point can both exist If no package declaration is used, an unnamed package is used by default READINGS AND EXERCISES Sections 8.2 and 5.4...
View Full Document

Page1 / 2

Lecture 16b - name as the package Ie. The physical setup...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online