Class Diagrams and Sequence Diagrams
1. Representing a class: State and Behaviour
From the given problem statement we can come up with different classes. Some
of them
are
shown
below:
- 1. WebBrowser
- 2. WebServer
- 3. RenderingEngine
- 4. BrowserControl
Note: Modeling of classes may differ from person to person. There is no
unique solution.
Let's focus on the Web Browser class and identify it's major states and
behaviours.
We will restrict ourselves only to conceptual class diagrams to keep things
simple.
Web Browser
States:
- currentURL: Indicating the page
being currently
loaded
- version: Indicating the browser
version
- addressBar: A place where one can
type in a URL
Behaviour:
- loadPage: Retrieve and display
a web page when
a URL is given
- reloadPage: Load the currently
open web page
again; no URL need to be
specified
Now let's represent these details pictorially.
In this way, we can represent other classes as well.
For example, let's see the Web Server class.
2. Association between Classes
Having represented the classes, let us see how one can relate different
classes. We
will
start
with
association.
Web Browser requests Web Server for a page. It can send requests to any
number of
web
servers,
including zero. The following figure represent this:
Web Server in turn sends a response back to the Web Browser. It is possible
that it
might
not
send
any response at all. We depict this below:
To represent unidirectional association, let us consider the Rendering
Engine and
File class.
3. Aggregation of Classes
Rendering Engine is a part of the Web Browser. A given Rendering Engine,
however, could
be a
part of more
than one Web Browser.
The above can be indicated by an aggregation.
4. Composition of Classes
Each Web Browser has it's own Browser Control. Without a Web Browser,
Browser Control
has no
existence.
Also, browsers typically have their own control logic. This can be
represented by a
composition
relationship.
6. Identifying Sequence of Activities
Now, let us consider how a web browser and a web server communicate. A
user types in
a
URL in
the
browser, and views the page. But something more happens under the hood
to display a
page.
When a user types in a URL and clicks on the "Go" button, the browser
sends a HTTP
Request to
the
concerned web server.
When the web server receives a HTTP Request from any client, it sends
back a HTTP
Response
to that
client.
On receiving a HTTP Response, web browser displays(renders) the
requested page.
Thus we have identified the two broad activities that take place when we
try to view
a
page
on a web
browser.
In the next scene, we will see how to represent these activities
sequentially in a
diagram
7. Drawing Sequence Diagrams
HTTP Response is shown with a open arrowhead and a dotted line. This
indicates that the
server
is returning
a message back to the browser.