Unit-2 Notes
Unit-2 Notes
Object-Oriented Concepts:
INTRODUCTION:
UML can be described as the successor of object-oriented (OO) analysis and design.
An object contains both data and methods that control the data. The data represents
the state of the object. A class describes an object and they also form a hierarchy to
model the real-world system. The hierarchy is represented as inheritance and the
Objects are the real-world entities that exist around us and the basic concepts such as
UML.
UML is powerful enough to represent all the concepts that exist in object-oriented
detail.
existing ones.
● Polymorphism − It defines the mechanism to exists in different forms
helps to understand the entities in the real world and how they interact
model and then proceed gradually. The conceptual model of UML can be mastered by
languages.
There are three basic steps where the OO concepts are applied and implemented. The
● Things
● Relationships
● Diagrams
Things
Things are the most important building blocks of UML. Things can be −
● Structural
● Behavioral
● Grouping
● Annotational
Structural Things
Structural things define the static part of the model. They represent the physical and
conceptual elements. Following are the brief descriptions of the structural things.
class.
Dashed ellipse
Use case −Use case represents a set of actions performed by a system for a specific
goal.
Node − A node can be defined as a physical element that exists at run time.
Behavioral Things
A behavioral thing consists of the dynamic parts of UML models. Following are the
behavioral things −
State machine − State machine is useful when the state of an object in its life cycle is
Grouping Things
Grouping things can be defined as a mechanism to group elements of a UML model
Package − Package is the only one grouping thing available for gathering structural
and comments of UML model elements. Note - It is the only one Annotational thing
Relationship
Relationship is another most important building block of UML. It shows how the
elements are associated with each other and this association describes the
functionality of an application.
Dependency
Dependency is a relationship between two things in which change in one element also
Association
Association is basically a set of links that connects the elements of a UML model. It
also describes how many objects are taking part in that relationship.
Generalization
Generalization can be defined as a relationship which connects a specialized element
world of objects.
Realization
Realization can be defined as a relationship in which two elements are connected. One
element describes some responsibility, which is not implemented and the other one
UML Diagrams
UML diagrams are the ultimate output of the entire discussion. All the elements,
relationships are used to make a complete UML diagram and the diagram represents a
system.
The visual effect of the UML diagram is the most important part of the entire process.
UML includes the following nine diagrams, the details of which are described in the
subsequent chapters.
● Class diagram
● Object diagram
● Sequence diagram
● Collaboration diagram
● Activity diagram
● Statechart diagram
● Deployment diagram
● Component diagram
Usecase diagram:
A use-case model is a model of how different types of users interact with the system to solve a problem.
As such, it describes the goals of the users, the interactions between the users and the system, and the
required behavior of the system in satisfying these goals.
A use-case model consists of a number of model elements. The most important model elements are: use
cases, actors and the relationships between them.
A use-case diagram is used to graphically depict a subset of the model to simplify communications.
There will typically be several use-case diagrams associated with a given model, each showing a subset
of the model elements relevant for a particular purpose. The same model element may be shown on
several use-case diagrams, but each instance must be consistent. If tools are used to maintain the
use-case model, this consistency constraint is automated so that any changes to the model element
(changing the name for example) will be automatically reflected on every use-case diagram that shows
that element.
The use-case model may contain packages that are used to structure the model to simplify analysis,
communications, navigation, development, maintenance and planning.
Much of the use-case model is in fact textual, with the text captured in the Use-Case Specifications that
are associated with each use-case model element. These specifications describe the flow of events of the
use case.
The use-case model serves as a unifying thread throughout system development. It is used as the
primary specification of the functional requirements for the system, as the basis for analysis and design,
as an input to iteration planning, as the basis of defining test cases and as the basis for user
documentation
The use-case model contains, as a minimum, the following basic model elements.
Actor
A model element representing each actor. Properties include the actors name and brief description. See
Concept: Actor for more information.
Use Case
A model element representing each use case. Properties include the use case name and use case
specification. See Artifact: Use Case and Concept: Use Case for more information.
Associations
Associations are used to describe the relationships between actors and the use cases they participate in.
This relationship is commonly known as a “communicates-association”.
Figure 1 shows a use-case diagram from an Automated Teller Machine (ATM) use-case model.
Use Case Diagrams
Use case diagrams are one of the five behavioral diagrams for modeling the dynamic
aspects of the system. A use case diagram specifies what the system does (behavior)
for the actors.
Use case diagram plays a key role in modeling the behavior of a system or subsystem
or a class. Each use case diagram consists of a set of use cases, actors and their
relationships.
Common Properties
Use case diagrams shares some common properties with the rest of the UML diagrams
like a name which identifies a use case diagram and the graphical content which is a
projection into a model.
Content
● Use cases
● Actors
● Dependency, generalization and association relationships
Like all other diagrams, use case diagrams may contain notes and constraints. They
may also contain packages or subsystems, which are used to group elements of your
model into larger chunks.
Common Uses
When we model the static use case view of a system, we apply use case diagrams in
one of the two ways:
● To model the context of a system
● To model the requirements of a system
Example:
1. Establish the context of the system by identifying the actors that surround (use)
the system.
2. For each actor, identify the behavior that the actor expects from the system or
requires the system to provide.
3. Name these common behaviors as use cases.
4. Use include and extend relationships to factor common behavior and optional
behavior.
5. Model these use cases, actors and their relationships in a use case diagram.
6. Use notes to provide details about the use cases and other non-functional
requirements.
Forward and reverse engineering
1. For each use case, identify the flow of events and its exceptional flow of events.
2. Generate a test script for each flow, using the flow’s preconditions as the test’s
initial state and its post conditions as its success criteria.
3. As necessary, simulate test runs to represent each actor that interacts with the
use case.
4. Use tools to run these tests each time you release the element to which the use
case diagram applies.
Class Diagrams
Class diagrams are most commonly found diagrams while modeling software systems.
A class diagram consists of classes, collaborations and interfaces. A class diagram is
used to model the static design view of the system.
Common Properties
The class diagram shares the common properties with the rest of the diagrams, a name
and graphical elements that are a projection into the model. What distinguish the class
diagram from the others are the contents of the diagram.
Contents
● Classes
● Interfaces
● Collaborations
● Generalization, dependencies and associations
Like other diagrams, class diagrams may also contain notes and constraints. Class
diagrams may also contain packages or subsystems which are used to organize the
elements into groups. Generally, the class diagrams are used for:
1. Identify the function or behavior of the part of a system you would like to model.
2. For each function or mechanism identify the classes, interfaces, collaborations
and relationships between them.
3. Use scenarios (sequence of activities) to walk through these things. You may find
new things or find that existing things are semantically wrong.
4. Populate the things found in the above steps. For example, take a class and fill
its responsibilities. Now, convert these responsibilities into attributes and
operations.
To model a schema,
1. Identify the classes whose state must be saved over the lifetime of the
application.
2. Create a class diagram and mark these classes as persistent by using tagged
values.
3. Provide the structural details for these classes like the attributes, associations
with other classes and the multiplicity.
4. Minimize the common patterns which complicate the physical database design
like cyclic associations, one-to-one associations and n-ary associations.
5. Provide the behavior for these classes by listing out the operations that are
important for data access and integrity.
6. Wherever possible, use tools to convert the logical design to physical design.
1. Identify the rules for mapping the models to the implementation language of your
choice.
2. Depending on the semantics of the language, you may want to restrict the
information in your UML models. For example, UML supports multiple
inheritance. But some programming languages might not allow this.
3. Use tagged values to specify the target language.
4. Use tools to convert your models to code.
Component Diagrams
A component is just a special kind of a diagram and shares the same common
properties as the other diagrams like: a name and graphical contents. What
distinguishes a component diagram from the rest of the diagrams is its content.
Content
● Components
● Interfaces
● Dependency, generalization, association and realization relationships.
Like all other diagrams, component diagrams may contain notes and constraints.
Component diagrams may also contain packages.
Common Uses
When modeling the static implementation view of a system, we will typically use
component diagrams in one of four ways:
● Either by forward or reverse engineering, identify the set of source code files of
interest and model them as components stereotypes as files.
● For larger systems, use packages to show groups of source code files.
● Consider using tagged values indicating such information as the version number
of the source code file, its author, and the date it was last changed.
● Model the compilation dependencies among these files using dependencies.
● Identify the classes in your model that represent your logical database schema.
● Select a strategy for mapping these classes to tables. You have to also consider
the physical distribution of your databases.
● To visualize, specify, construct and document your mapping, create a component
diagram that contains components stereotyped as tables.
● Where possible, use tools to help you transform your logical design into a
physical design.
Modeling adaptable systems
● Consider the physical distribution of the components that may migrate from node
to node. We can specify the location of a component instance by marking it with
a location tagged value.
● If you want to model the actions that cause a component to migrate, create a
corresponding interaction diagram that contains component instances. We can
illustrate a change of location by drawing the same instance more than once, but
with different values for its location tagged value.
Interaction Diagrams
Introduction
Interaction diagrams share the properties which are common to all the diagrams in
UML. They are: a name which identifies the diagram and the graphical contents which
are a projection into the model.
Contents
1. Objects
2. Links
3. Messages
Sequence Diagrams
A sequence diagram is one of the two interaction diagrams. The sequence diagram
emphasizes on the time ordering of messages. In a sequence diagram, the objects that
participate in the interaction are arranged at the top along the x-axis.
Generally, the object which initiates the interaction is placed on the left and the next
important object to its right and so on. The messages dispatched by the objects are
arranged from top to bottom along the y-axis. This gives the user the detail about the
flow of control over time.
Sequence diagram has two features that distinguish them from collaboration diagrams.
First, there is the object lifeline, which is a vertical dashed line that represents the
existence of an object over a period of time. Most of the objects are alive throughout the
interaction.
Objects may also be created during the interaction with the receipt of the message
stereotyped with create. Objects may also be destroyed during the interaction with the
receipt of the message stereotyped with destroy.
Second, there is focus of control which is represented as a thin rectangle over the life
line of the object. The focus of control represents the points in time at which the object
is performing an action. We can also represent recursion by using a self message.
Collaboration Diagrams
A collaboration diagram is made up of objects which are the vertices and these are
connected by links. Finally, the messages are represented over the links between the
objects. This gives the user the detail about the flow of control in the context of
structural organization of objects that collaborate.
Collaboration diagram has two features that distinguish them from the sequence
diagrams. First, there is a path which indicates one object is linked to another. Second,
there is a sequence number to indicate the time ordering of a message by prefixing the
message with a number.
Common Uses
We use interaction diagrams to model the dynamic aspects (interactions) of the system.
When we use an interaction diagram to model some dynamic aspect of a system, we do
so in the context of the system as a whole, a subsystem, an operation or a class. We
typically use the interaction diagrams in two ways:
1. Set the context for the interaction, whether it is a system, subsystem, operation
or class or one scenario of a use case or collaboration.
2. Identify the objects that take part in the interaction and lay them out at the top
along the x-axis in a sequence diagram.
3. Set the life line for each object.
4. Layout the messages between objects from the top along the y-axis.
5. To visualize the points at which the object is performing an action, use the focus
of control.
6. To specify time constraints, adorn each message with the time and space
constraints.
7. To specify the flow of control in a more formal manner, attach pre and post
conditions to each message.
1. Set the context for the interaction, whether it is a system, subsystem, operation
or class or one scenario of a use case or collaboration.
2. Identify the objects that take part in the interaction and lay them out in a
collaboration diagram as the vertices in a graph.
3. Set the initial properties of each of these objects.
4. Specify the links among these objects.
5. Starting with the messages that initiate the interaction, attach each subsequent
message to the appropriate link, setting its sequence number, as appropriate.
Use Dewey numbering system to specify nested flow of control.
6. To specify time constraints, adorn each message with the time and space
constraints.
7. To specify the flow of control in a more formal manner, attach pre and post
conditions to each message.
Object diagrams
Before learning about object diagrams in UML, have a look at class diagrams in UML.
Object diagrams allow us to model the static design view or static process view. It
involves modeling a snapshot of the system which contains objects (instances), their
state and links between objects.
An object diagram represents the static part of an interaction containing the objects that
communicate and the links between them without any messages.
Common Properties
An object diagram shares the same common properties like the rest of the diagrams, a
name which identifies the diagram and graphical contents which are a projection into
the model. What distinguish an object diagram from the rest of the diagrams are its
contents.
Contents
● Objects
● Links
Like all other diagrams, object diagrams may contain notes and constraints.
Object diagrams may also contain packages and subsystems which are used to group
the related elements in the model together. Sometimes we can also include classes in
the object diagrams. Generally, object diagrams are used to model the object structures.
● First, identify the function or behavior or part of a system you want to model as
collection of classes, interfaces and other things.
● For each function or mechanism identify the classes and interfaces that
collaborate and also identify the relationships between them.
● Consider a scenario (context) that walks through this mechanism and freeze at a
moment in time and identify the participating objects.
● Represent the state of objects by listing out the attributes and their values.
● Represent the links between objects which are instances of associations.
Forward and Reverse Engineering
Table Of Contents
Functional Programming
Procedural Programming
Object oriented Programming
Functional vs Procedural vs OOPs
Functional Programming
In recent years, JavaScript, a functional programming language that has accumulated
more popularity recently, has brought attention to the functional programming paradigm.
Language independence is one of the benefits of functional programming, which has its
roots in mathematics. Executing a series of mathematical functions is the key principle
of this paradigm.
Functional Programming
1. Pure Functions
There are two main characteristics of these functions. Their output is the same for the
same arguments regardless of any other factor.
The second advantage is that they do not have any side-effects, that is, they do not
modify any arguments or local/global variables or input/output streams.
Immutability is one of the more recent properties. The value returned by a pure function
is its only result. The results are deterministic.
The function-based programming approach makes debugging programs easy due to the
lack of side effects and hidden input/output. Using pure functions also simplifies the
process of writing parallel/concurrent applications.
As long as the input does not change, a smart compiler can parallelize the instructions,
evaluate results when needed, and memorize the results since the results never change
as long as the input does not.
return x + y;
};
2. Recursion
Unlike the other programming paradigm, functional programming does not employ for
and while loops. Recursion is used instead for iteration in these languages. Recursive
functions are used to execute recursion, which calls themselves continually until the
base case is obtained.
public class Recursion {
if (n == 1)
return 1;
else
3. Referential Transparency
In functional programming, variables cannot change their values once they have been
defined. As a result, there is referential transparency. By using this method, the same
language expression will produce the same result.
Since variables may be replaced with their actual values at any time during the
execution of the program, Referential transparency eliminates the slightest possibility of
undesirable effects.
The functional programming style treats functions as variables. Thus, they qualify as
first-class functions. A data structure is a collection of characteristics that can be passed
around as parameters or returned from functions or stored in data structures.
Functions that take other functions as arguments or return functions are higher-order
functions. Functions that are first-class in functional programming languages can be
higher-order functions.
5. Immutability
In the case of variables, they are immutable, meaning they cannot be modified once
they've been initialized. A new variable, however, can be created. Varables are
immutable, so they maintain state throughout the program.
// class is declared final
final class Immutable {
this.name = name;
this.date = date;
return name;
return date;
}
}
class Main {
The reason why functional programs are easier to verify is because their states
do not change during their execution. Functional programs can thus be modeled
and reasoned more easily this way.
In Concurrent programming, multiple tasks are executed concurrently (not
neccessarily simultaneously) while in parallel programming, mulitple tasks are
executed parallely (simultaneously).
Compilers can optimize and substituting complex expressions into simpler ones
easily. Compilers are given more flexibility in rearranging expressions because of
referential integrity.
Because functions are independent of one another, programs are guaranteed to
be secure and safe. The problem of leaks of critical information and accidental
modifications of data is now over.
Programs can be expressed elegantly.
C++
Python
Java
Lisp
Haskell
Julia
Examples of Applications
Procedural Programming
In programming, it is defined as a language derived from structure programming and
based on the use of call procedures. Essentially, procedures are the functions, routines,
or subroutines that specify the computational steps that need to be performed.
The process involves breaking a task down into variables and routines by following a
series of instructions. Programs can call procedures at any point during execution,
either by other procedures or by themselves.
Procedural Programming
Procedural programming can be done in ALGOL, COBOL, BASIC, PASCAL,
FORTRAN, and C.As Procedural programming is considered to be less secure than
object-oriented programming.
System.out.println(text);
1. Scoping
The scoping concept is concerned with setting the locality of entities (objects) within a
procedural program. Without explicit permission, scoping prevents non-local variables
from being accessed from other procedures.
2. Modularity
Using this method, components are broken down into interchangeable chunks of
functionality that can be reused and shared.
3. Parameter Passing
A Parameters can be passed into a procedure call via this mechanism. It is possible to
pass parameters as references or as values.
The data is publicly accessible. Data can be accessed and modified without
restriction. As a result, unintended alterations occur and serious mistakes are
more likely to be committed.
Rather than focusing on data organization, this approach emphasizes
procedures. Concepts can be obscured by this, making it difficult to map them
into code.
Python
Dart
Swift
Rust
Bash
PowerShell