UNIT 1 Compressed
UNIT 1 Compressed
UNIT 1 Compressed
•Object orientation
•Object Identity
•Generosity
•Importance of Modelling-Principles
•Architecture
•Object Orientation
•Object-oriented analysis and design (OOAD) is a technical approach for analyzing and
designing an application, system, or business by applying object-oriented programming, as well as
using visual modelling throughout the software development process to guide stakeholder
communication and product quality.
•What does Object-oriented mean?
•Object-oriented refers to a programming language, system or software methodology that is built on the
concepts of logical objects.
•It works through the creation, utilization and manipulation of reusable objects to perform a specific task, process
or objective.
•The essence of object-oriented is that each of the created objects can be reused in the same and other
programs and applications.
•The object-oriented approach, however, focuses on objects that represent abstract or concrete things in the
real world. These objects are first defined by their character and their properties, which are represented by their
internal structure and their attributes (data). The behavior of these objects is described by methods (functions).
•Objects form a capsule, which combines the characteristics with behavior.
•Objects are intended to enable programmers to map a real problem and its proposed software solution on a
one-to-one basis.
•Object Oriented Programming
•Object Oriented programming (OOP) is a programming paradigm that relies on
the concept of classes and objects.
•It is used to structure a software program into simple, reusable pieces of code
blueprints (usually called classes), which are used to create individual instances of
objects.
•We could then set the value of the properties defined in the class to describe my
car, without affecting other objects or the class template.
•We can then reuse this class to represent any number of cars.
•Our car class may have a method repaint that changes the colour attribute of our
car. This function is only helpful to objects of type car, so we declare it within the
car class thus making it a method.
String repaint(colorchange)
color=colorchange;
Return color;
Func {}
main()
Car obj()
obj.model=xyz;
obj.color=blue;
obj.brand=hyundai;
Car obj1;
obj1.model=xyz;
obj1.color=blue;
obj1.brand=hyundai;
Obj.repaint(red);
}
•Uses of Object Orientation
• Methods
• Attributes
• Objects
•Classes
•classes are essentially user defined data types. Classes are where we create a
blueprint for the structure of methods and attributes. Individual objects are
instantiated, or created from this blueprint.
•Classes contain fields for attributes, and methods for behaviours and represent
broad categories, like car or dog that share attributes.
•These classes define what attributes an instance of this type will have, like color,
but not the value of those attributes for a specific object.
•Classes can also contain functions, called methods available only to objects of
that type. These functions are defined within the class and perform some action
helpful to that specific type of object.
Objects
Objects are instances of classes created with specific data, for example in
the code snippet below Rufus is an instance of the dog class.
The state of an object is defined by the data in the object’s attributes fields.
For example, a puppy and a dog might be treated differently at pet camp. The
birthday could define the state of an object, and allow the software to handle
dogs of different ages differently.
•Methods: Methods represent behaviors. Methods perform actions; methods might
return information about an object, or update an object’s data. The method’s code
is defined in the class definition.
When individual objects are instantiated, these objects can call the methods
defined in the class.
The state of an object is defined by the data in the object’s attributes fields.
• class Parrot:
• # class attribute
• # instance attribute
• self.name = name
•print("Blu is a {}".format(blu.__class__.species))
• Inheritance: child classes inherit data and behaviors from parent class.
• Abstraction: only exposing high level public methods for accessing an object.
•Specifically, consider that the final software system is the lowest level of abstraction.
All of the software's design details are present at this level. Information hiding allows
us to hide information unnecessary to a particular level of abstraction within the final
software system, allowing for software engineers to better understand, develop and
maintain the software.
•an abstraction relates to how an object and its behaviors are presented to the
user and encapsulation is a methodology that helps create that experience.
•Think about the interface of your mobile phone. Whether you use an Android
operating system or iOS, you don't interact directly with the code that allows
your phone to connect to the internet, send a text message or play a video
game. Instead, you interact with the code through a user interface that is
designed to streamline your experience and make it easy to access the
functions and methods you need to complete a task. In this case, the interface
is abstracted away from the actual implementation of the code.
•Inheritance
•Inheritance allows classes to inherit features of other classes.
•If basic attributes and behaviors are defined in a parent class, child classes can be
created extending the functionality of the parent class, and adding additional
attributes and behaviors.
•The benefits of inheritance are programs can create a generic parent class, and
then create more specific child classes as needed. This simplifies overall
programming, because instead of recreating the structure of the class multiple
times, child classes automatically gain access to functionalities within their
parent class.
•Types of Inheritance
✦Single Inheritance − A subclass derives from a single super-class.
✦Multilevel Inheritance − A subclass derives from a super-class which in turn is derived from another class
and so on.
✦Hierarchical Inheritance − A class has a number of subclasses each of which may have subsequent
subclasses, continuing for a number of levels, so as to form a tree structure.
✦Hybrid Inheritance − A combination of multiple and multilevel inheritance so as to form a lattice structure.
•Polymorphism
•Polymorphism means designing objects to share behaviors. Using inheritance,
objects can override shared parent behaviors, with specific child behaviors.
•With object identity, objects can contain or refer to other objects. Identity is a
property of an object that distinguishes the object from all other objects in the
application.
•An object retains its identity even if some or all of the values of variables or
definitions of methods change over time.
•Several forms of identity:
◦ value: A data value is used for identity (e.g., the primary key of a tuple in a
relational database).
◦ name: A user-supplied name is used for identity (e.g., file name in a file
system).
•The object identity of two objects of the same type is the same, if every change
to either object is also a change to the other object.
Modelling
•Model is a simplification of reality.
1. Activity diagrams
2. Interaction diagrams
• The structural and the behaviour elements of the system are there in this system.
✓The right models will simplify even the most wicked problem, offering insights
that couldn’t have been gained otherwise.
The wrong models will mislead us, causing to focus on irrelevant issues.
• Principle 2: Every model maybe expressed at different levels of abstraction.
• Example: An analyst or an end user will want to focus on issues of what while
a developer would like to address the issues of how.
•
• Principle 3: The best models are connected to reality.
•
• Principle 4: No single model is sufficient, a set of models is needed to solve any non-trivial system
• To understand the architecture of such a system, we need several complementary and interlocking
views:
A design view (capturing the vocabulary of the problem space and solution space).
An interaction view (showing interaction among parts of the system and between the system
and environment).
•In analysis phase, OO models are used to fill the gap between problem and
solution. It performs well in situation where systems are undergoing continuous
design, adaption, and maintenance. It identifies the objects in problem domain,
classifying them in terms of data and behavior.
•The OO model is beneficial in the following ways −
•Encapsulation
•Abstraction
•Relationships
•Inheritance
•Polymorphism
Elements of Object-Oriented System
Objects − An object is something that is exists within problem domain and can be
identified by data (attribute) or behavior. All tangible entities (student, patient) and some
intangible entities (bank account) are modeled as object.
Behavior − It specifies what the object can do. It defines the operation performed on
objects.
Class − A class encapsulates the data and its behavior. Objects with similar meaning
and purpose grouped together as class.
Methods − Methods determine the behavior of a class. They are nothing more than an
action that an object can perform.
Message − A message is a function or procedure call from one object to another. They
are information sent to objects to trigger methods. Essentially, a message is a function
or procedure call from one object to another.