What are composite structure
diagram and reflexive association in class diagrams?
Composite structure
diagram When we try to show Aggregation and Composition in a complete
project the diagram becomes very complicated so in order to keep it simple we
can use Composite structure diagram. In the below figure we have shown two
diagrams one is normal diagram other is Composite structure diagram and the
simplicity can easily be identified. In the composite diagram the aggregated
classes are self contained in the main class which makes it simpler to read.
Figure: - Composite
Structure diagram
Reflexive
associations In many scenarios you need
to show that two instances of the same class are associated with each other and
this scenario is termed as Reflexive Association. For instance in the below
figure shows Reflexive Association in the real project. Here you can see
customer class has multiple address class and addresses can be a Head office,
corporate office or Regional office. One of the address objects is Head office
and we have linked the address object to show Reflexive Association
relationship. This is the way we can read the diagram Regional address object is
blocked by zero or one instance of Head office object.
Figure: - Reflexive
association
Can you
explain business entity and service class?
Business entity objects represent persistent
information like tables of a database. Just making my point clearer they just
represent data and do not have business validations as such. For instance below
figure ‘Business entity and service’ shows a simple customer table which with
three fields ‘Customer Code’,’ Customer Address’ and ‘Phone Number’. All these
fields are properties in ‘ClsCustomer’ class. So ‘ClsCustomer’ class becomes the
business entity class. The business entity class by itself can not do anything
it’s just a place holder for data. In the same figure we have one more class
‘ClsServiceCustomer’. This class aggregates the business entity class and
performs operations like ‘Add’,’ Next’ (Move to next record), ‘Prev’ (Move to
previous record) and ‘GetItem’ (get a customer entity depending on
condition).
With this approach we have separated the data from the
behavior. The service represents the behavior while the business entity
represents the persistent data.
Figure:-Business
entity and service
Can you
explain System entity and service class?
System entity class represents persistent
information which is related to the system. For instance in the below figure
‘System entity and service class’ we have a system entity class which represents
information about ‘loggedindate’ and ‘loggedintime’ of the system registry.
System service class come in two flavors one is it acts like a wrapper in the
system entity class to represent behavior for the persistent system entity data.
In the figure you can see how the ‘ClsAudit’ system entity is wrapped by the
‘ClsAuditSytem’ class which is the system service class. ‘ClsAuditSystem’ adds
‘Audit’ and ‘GetAudit’ behavior to the ‘ClsAudit’ system entity class.
Figure: - System
entity and service class
The other flavor of the system service class is to
operate on non-persistent information. The first flavor operated on persistent
information. For instance the below figure ‘Non-persistent information’ shows
how the class ‘ClsPaymentService’ class operates on the payment gateway to Check
is the card exists , Is the card valid and how much is the amount in the card ?.
All these information are non-persistent. By separating the logic of
non-persistent data in to a system service class we bring high reusability in
the project.
Figure: -
Non-persistent information
Note: - The
above question can be asked in interview from the perspective of how you have
separated the behavior from the data. The question will normally come twisted
like ‘How did you separate the behavior from the data?’.
Can you
explain generalization and specialization?
Generalization and
specialization In
Generalization and Specialization we define the parent-child relationship
between the classes. In many instance you will see some of the classes have same
properties and operation these classes are called super class and later you can
inherit from super class and make sub classes which have their own custom
properties. In the below figure there are three classes to show Generalization
and Specialization relationship. All phone types have phone number as a
generalized property but depending upon landline or mobile you can have wired or
simcard connectivity as specialized property. In this diagram the clsphone
represent Generalization whereas clslandline and clsmobile represents
specialization.
Figure: -
Generalization and Specialization
How do we represent an abstract
class and interface UML?
Interface is represented by <<type>> in
the class diagram. Below figure ‘Interface in action’ shows we have defined an
interface ‘IContext’. Note the ‘<<type>>’ represents an interface.
If we want to show that the interface is used in a class we show the same with a
line and a simple circle as shown in figure ‘Interface in Action’ below.
Figure: - Interface
in action
Abstract classes are represented by ‘{abstract}’ as
shown in figure ‘Abstract classes in action’.
Figure: - Abstract
classes in action.
How do we achieve generalization
and specialization?
By using inheritance.
Can you explain object diagrams in
UML?
Class represents shows the static nature of the
system. From the previous question you can easily judge that class diagrams
shows the types and how they are linked. Classes come to live only when objects
are created from them. Object diagram gives a pictorial representation of class
diagram at any point of time. Below figure ‘Object diagram’ shows how a class
looks in when actual objects are created. We have shown a simple student and
course relationship in the object diagram. So a student can take multiple
courses. The class diagram shows the same with the multiplicity relationship. We
have also shown how the class diagram then looks when the objects are created
using the object diagram. We represent object with Object Name: Class Name. For
instance in the below figure we have shown ‘Shiv : ClsStudent’ i.e ‘Shiv’ is the
object and ‘ClsStudent’ the class. As the objects are created we also need to
show data of the properties, the same is represented by ‘PropertyName=Value’
i.e. ‘StudentName=Shiv’.
Figure: - Object
diagrams
The diagram also states that ‘ClsStudent’ can apply
for many courses. The same is represented in object diagram by showing two
objects one of the ‘Computer’ and the other of ‘English’.
Note: - Object
diagrams should only be drawn to represent complicated relationship between
objects. It’s possible that it can also complicate your technical document as
lot. So use it sparingly.
Can you explain sequence diagrams?
Sequence
diagrams Sequence diagram shows
interaction between objects over a specific period time. Below figure 'Sequence
diagram' shows how a sequence diagram looks like. In this sequence diagram we
have four objects 'Customer','Product','Stock' and 'Payment'. The message flow
is shown vertically in waterfall manner i.e. it starts from the top and flows to
the bottom. Dashed lines represent the duration for which the object will be
live. Horizontal rectangles on the dashed lines represent activation of the
object. Messages sent from a object is represented by dark arrow and dark arrow
head. Return message are represented by dotted arrow. So the figure shows the
following sequence of interaction between the four objects:-
• Customer object sends
message to the product object to request if the product is available or
not. • Product object sends message to the stock object to see if the product
exists in the stock. • Stock object answers saying yes or No. • Product
object sends the message to the customer object. • Customer object then sends
a message to the payment object to pay money. • Payment object then answers
with a receipt to the customer object.
One of the points to be
noted is product and stock object is not active when the payment activity
occurs.
Figure: - Sequence
diagram
Messages in sequence
diagrams There are five different
kinds of messages which can be represented by sequence Synchronous and
asynchronous messages:- Synchronous messages are
represented by a dark arrow head while asynchronous messages are shown by a thin
arrow head as shown in figure ‘Synchronous and Asynchronous’.
Figure: -
Synchronous and Asynchronous
Recursive
message:- We have scenarios where we
need to represent function and subroutines which are called recursively.
Recursive means the method calling himself. Recursive messages are represented
by small rectangle inside a big rectangle with an arrow going from the big
rectangle to the small rectangle as shown in figure ‘Recursive
message’.
Figure: - Recursive
message
Message
iteration:-
Message iteration
represents loops during sequences of activity. Below figure ‘message iteration’
shows how ‘order’ calls the ‘orderitem’ objects in a loop to get cost. To
represent loop we need to write ‘For each <<object name>>’. In the
below figure the object is the ‘orderitem’. Also note the for each is put in a
box to emphasize that it’s a loop.
Figure: - Message
iteration
Message
constraint:- If we want to represent
constraints it is put in a rectangle bracket as shown in figure ‘message
constraint’. In the below figure ‘message constraint’ the ‘customer’ object can
call ‘book tickets’ only if the age of the customer is greater than
10.
Figure: - Message
constraint
Message
branching:- Below figure ‘message
branching’ shows how ‘customer’ object have two branches one is when the
customer calls save data and one when he cancels the data.
Figure: - Message
branching
Doing Sequence diagram
practically Let’s take a small example
to understand sequence diagram practically. Below is a simple voucher entry
screen for accounts data entry. Following are the steps how the accountant will
do data entry for the voucher:-
Ø
Accountant loads the voucher data entry screen. Voucher screen
loads with debit account codes and credit account codes in the respective combo
boxes.
Ø
Accountant will then fill in all details of the voucher like
voucher description, date, debit account code, credit account code, description,
and amount and then click ‘add voucher’ button.
Ø
Once ‘add voucher’ is clicked it will appear in the voucher screen
below in a grid and the voucher entry screen will be cleared and waiting for new
voucher to be added. During this step voucher is not added to database it’s only
in the collection.
Ø
If there are more vouchers to be added the user again fills
voucher and clicks ‘add voucher’.
Ø
Once all the vouchers are added he clicks ‘submit voucher’ which
finally adds the group of vouchers to the database.
Below figure ‘Voucher data entry screen’ shows
pictorially how the screen looks like.
Figure: - Voucher
data entry screen
Figure ‘Voucher data entry sequence diagram’ shows
how the sequence diagram looks like. Below diagram shows a full sequence diagram
view of how the flow of the above screen will flow from the user interface to
the data access layer. There are three main steps in the sequence diagram, let’s
understand the same step by step.
Step
1:- The accountant loads the voucher data entry screen. You can see from
the voucher data entry screen image we have two combo boxes debit and credit
account codes which are loaded by the UI. So the UI calls the ‘Account Master’
to load the account code which in turn calls the data access layer to load the
accounting codes.
Step 2:- In this
step the accountant starts filling the voucher information. The important point
to be noted in this step is that after a voucher is added there is a conditional
statement which says do we want to add a new voucher. If the accountant wants to
add new voucher he again repeats step 2 sequence in the sequence diagram. One
point to be noted is the vouchers are not added to database they are added in to
the voucher collection.
Step 3:-
If there are no more vouchers the accountant clicks submit and finally adds the
entire voucher in the database. We have used the loop of the sequence diagram to
show how the whole voucher collection is added to the database.
Figure: - Voucher
data entry sequence diagram
|