Access Modifiers | Private, Public & ProtectedAn access modifier determines the visibility of a class member (states & behaviours).An access modifier of Public allows a class member to be accessed from external objects & is denoted on a class diagram with a + (addition) symbol. A Private access modifier allows only internal access and prevents access by external objects. Private access is denoted on a class diagram with the - (minus) symbol. The Protected access modifier allows internal access and access by child classes. Protected access is denoted on a class diagram with the # (hash) symbol. |
Showing posts with label UML. Show all posts
Showing posts with label UML. Show all posts
Tuesday, January 8, 2013
Access Modifiers | Private, Public & Protected
Labels:
Access Modifier,
class,
Private,
protected,
Public,
UML,
Visibility
Tuesday, May 29, 2012
Sunday, May 27, 2012
What is a Sequence Diagram?
A sequence diagram is a UML (Unified Modelling Language) diagram. It is used to show the interactions between objects in the sequence they occur.
Here is a class diagram of the objects in the system...
Where a class diagram shows the details of each class & the relationships between them; a sequence diagram shows the sequential interactions between these objects.
Lifelines
Each object has a lifeline. This is a dashed line. The solid areas denote when an object is active in a process.
"UML basics: The sequence diagram" ( http://ibm.co/Lk8yqN )
err....here's a cat:
Here is a class diagram of the objects in the system...
The sequence diagram below, models the interactions required to get the 'Message' from the SpecialPower object.
Where a class diagram shows the details of each class & the relationships between them; a sequence diagram shows the sequential interactions between these objects.
Lifelines
Each object has a lifeline. This is a dashed line. The solid areas denote when an object is active in a process.
Numbering
Notice that each interaction in the sequence diagram is numbered according to the sequential flow of execution.
Void
In design documentation, where no value is returned from an interaction, the word 'void' is often used. A 'void' return is often seen as the result of instantiating an object. This is because a constructor cannot return a value. As well as that, you could expect to see 'void' as the return from a sub procedure.
"UML basics: The sequence diagram" ( http://ibm.co/Lk8yqN )
err....here's a cat:
What is a Constant? Final keyword
DOWNLOAD THE CODE: FinalValuePkg
We can store a value in a constant. Very similar to a variable except that a constant has a constant value. That is, the stored value is never changed as a result of processing.
Constants are used where a value should never be changed such as a maximum, minimum, number of hours in a day, days in a week, etc.
A constant begins with the keyword final. Just as with a variable, a type & identifier must be given.
CIRCLE_WIDTH and CIRCLE_HEIGHT are defined using uppercase and have each been assigned a value.
"Java Syntax: Declaring and Using Constants in Java" ( http://bit.ly/JmgF5S )
Here's a cat:
We can store a value in a constant. Very similar to a variable except that a constant has a constant value. That is, the stored value is never changed as a result of processing.
Constants are used where a value should never be changed such as a maximum, minimum, number of hours in a day, days in a week, etc.
A constant begins with the keyword final. Just as with a variable, a type & identifier must be given.
The compiler will not allow any processing statements to change the values of these constants.
UML Class Diagram Notation
The UML Class Diagram notation for a constant (final) is as below:
CIRCLE_WIDTH and CIRCLE_HEIGHT are defined using uppercase and have each been assigned a value.
"Java Syntax: Declaring and Using Constants in Java" ( http://bit.ly/JmgF5S )
Here's a cat:
Monday, May 21, 2012
Unified Modelling Language - UML
"Unified Modeling Language - Wikipedia, the free encyclopedia" ( http://bit.ly/Lk7zXy )
"UML basics: The class diagram" ( http://ibm.co/Jwpxv3 )
"UML basics: The sequence diagram" ( http://ibm.co/Lk8yqN )
"Activity diagram - Wikipedia, the free encyclopedia" ( http://bit.ly/Jwq4Nu )
Friday, May 18, 2012
The 'static' keyword
Download the code
Static variables & methods are associated with the class rather than an instance of an object of that class.
Usually, the data contained within an object, belongs only to that instance.
If you want all instances of a class to share some data, use a static variable. A static variable belongs to the class, rather than an instance the class (object).
The example below uses a static variable to keep count of the number of Widget objects that have been created.
The Widget class contains a single static variable called _numberOfWidgets. No matter how many instances of Widget are created, there will be a single value associated with the _numberOfWidgets variable.
A static method is provided to set the value of _numberOfWidgets and a static method is provided to get the value of _numberOfWidgets. In this example, the constructor calls the set method and in turn, the set method increments the value.
In the TestWidgetClass below, a number of Widget instances are created. Note that the call to the get_numberOfWidgets method is made by referencing the class directly, rather than by instance of the class.
And the output is:
"Understanding Instance and Class Members (The Java™ Tutorials > Learning the Java Language > Classes and Objects)" ( http://bit.ly/KmbYd7 )
In a UML class diagram, Static variables & methods are represented with an underline.
Here's a cat to keep you calm:
Labels:
cat,
Class diagram,
Method,
Reserved keywords,
Static,
UML,
Variables
Tuesday, April 24, 2012
Constructors and instantiation
"Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)" ( http://bit.ly/I67fRB )
Every class has at least one Constructor. This is a special method that prepares the object for use. It has the same name as the class.
In UML notation, the constructor is always referred to as new(). This is because UML is language independent and not Java specific. Different programming languages have different rules for naming a constructor.
Every class has at least one Constructor. This is a special method that prepares the object for use. It has the same name as the class.
A class can have multiple constructors - this is known as method overloading.
The constructor is always the first method called on an object. Think of it as an 'on-switch'. When we instantiate an object of a class, we call it's constructor using the new keyword:
Syntax:
Type identifier = new Type(parameters, if any);
Example:
Telephone myTelephone = new Telephone();
Labels:
class,
Constructor,
declare,
Instantiation,
new,
Objects,
Reserved keywords,
UML
Subscribe to:
Posts (Atom)












