Friday, January 26, 2018

Object Oriented Concept


Question 01


i. Which of the following is not an attribute of complex systems?
A. Hierarchic structure.
B. Easy to disassemble.
C. Stable intermediate forms.
D. Separation of concerns.


Complex Systems and software complexity


Driven by complexity
The complexity of massive scale software systems exceeds the abilities to understand
all the subtle elements of its design. This is evidently an inherent property of these
systems. We have to master it, we cannot eliminate it.


World Complexity
More and more software systems have to directly deal with real world complexity.
(ex: think of fly-by-the-wire airplanes or self-driving cars) The complexity of the real
world is virtually limitless and we often have to model it by stochastic processes, rather
than deterministically. Effectively, there is no limit to how complex we can/should make
our software.


Development issues
Then there is the problem of the software itself affecting planning; as it starts coming
to life, it influences the design plan. (ex: after some design/development, we see issues
we could not anticipate) This feedback increases complexity.


Five attributes of complex systems


  1. Hierarchic Structure
More complex systems are (or can be) thought as having a hierarchical structure.
In some cases this is : self evident, In many cases this is : a conceptual way for us to
depict them. Without the hierarchical structure we couldn’t be able to see or talk
about complex systems.
The hierarchical structure is essential to the functioning of the system, as much as
how the parts work.
  1. Relative Primitives
Regarding the nature of the primitive components of a complex system, our
experience suggests that:
The choice of what components in a system are primitive is relatively arbitrary
and is largely up to the discretion of the observer of the system.
What is primitive for one observer may be at a much higher level of abstraction
for another.


  1. Separation of Concerns
These hierarchical, complex systems are to some extent decomposable (parts
work per software engineer), but more often are to be modelled as nearly
decomposable because there are in fact dependences  among parts.
While it’s essential that intra-component dependencies are stronger than
inter-component ones, the latter are often there.
Separation of concerns means, Identifying components that minimize
inter-component linkages is essential if we want to be able to deal with them
independently.


  1. Common Patterns
Complex systems have common patterns. These patterns may involve the
reuse of small components with minimal variations, such as the cells found in
both plants and animals, or of larger structures, such as vascular systems, also
found in both plants and animals.
This is a useful property from the point of view of analysing and modelling these
systems.


  1. Stable Intermediate Forms / Evolution
As systems evolve, objects that were once considered complex become the
primitive objects, on which more complex systems are built. Furthermore, we
can never craft these primitive objects correctly the first time: We must use them
in context first and then improve them over time as we learn more about the real
behavior of the system.
As systems evolved, previous systems can become primitives. Think of the
evolution from unicellular to multicellular organisms.


Ii. In a complex system a primitive is
A. a component that is not further decomposed in the hierarchy.
B. a software system before it is re-designed.
C. an initial hierarchy.
D. a native datatype.


Iii. Which of the following is true about complex system components:
A. They are completely decomposable into independent parts.
B. They may have dependencies between them.


iv. Abstraction is the process of:
A. Creating the most general implementation of an object.
B. Identifying the most important characteristics of the objects that
make up a problem domain.
C. Removing details from an object.
D. Making an object reusable.


Principles/elements of Object model


Major elements


Abstraction (entity, action, virtual machine, coincidental)
  • To hide information that is not relevant or rather show only relevant
information and to simplify it by comparing it to something similar in the world.
  • The process of forming of general and relevant concept from more
complex scenarios.
  • It is the key to simplify a complex design into smaller, manageable parts
which then become the components of a bigger and complex system.
  • It is the idea of hiding the complexity within a smaller/simple component
of a system.
  • Based on observable behaviour of an object.
  • Denotes essential characteristics of an object that will distinguish it from
all other kinds of objects.
  • Provide crisply defined conceptual boundaries, relative to the perspective
of the viewer.
  • Focuses on outside of the object, not its implementation.
Principle of least commitment :
interface of an object provides its essential behaviour,
nothing more.
Principle of least astonishment :
Abstraction captures the entire behaviour of some object,
no more no less and offers no surprises/ side effects beyond
the scope of abstraction.


Encapsulation (heart of OOP)
  • The localization of the information or knowledge within an object, also called
as information hiding.
  • Objects encapsulate data and implementation details to the outside world.
An object is a black box that exhibits only a certain behaviour.




  • The behavior of this object is useful to the external world or other objects.
  • An object encompass its behaviour by means of methods or functions.
  • The set of functions an object exposes to other objects or external world acts
as the interface of the object.
  • Advantages :
    • Code becomes more flexible, easy to change with new requirements,
                    without breaking the code of others who use our code.
    • Makes unit testing easy.
    • Can control who can see what.
    • Can write unchangeable classes.

Abstraction
Encapsulation
Based on the observable
behaviour of an object
Focuses on the implementation
that gives rise to that behaviour,
even though it hides how it does it.

Modularity (packaging in java)
  • Especially for larger applications, we have hundreds of classes in them,
  • by using modules is essential to help manage complexity.
  • Modules serve as the physical containers in which we declare the classes
and objects of our design.
  • Decompose system into a set of cohesive and loosely coupled modules.
  • Group logically related abstractions (classes)
  • Minimize dependencies among modules (make each data abstraction
private to one module)


An object ideally provide a crisp boundary, around a single abstraction, and both
encapsulation and modularity provide barriers around this abstraction.


Hierarchy (inheritance in java)
  • A ranking or ordering of abstractions(classes)
  • A set of abstractions often forms a hierarchy, by identifying hierarchies in our
design, we can understand our problem in a simple way.
  • Inheritance is a mechanism of defining a new class based on an existing class.
    • Existing class : parent class, super class
    • Derived class : child class, sub class
  • Inheritance defines a relationship among classes, from where, one class shares
the structure or behaviour defined in one or more classes.
    • Single inheritance


    • Multiple inheritance (not in java)


Multi Level inheritance (allowed in java)
vehicles-multi-level-hierarchy-2ae71f7f7869a8bc77de95f843a5b8f5.png


  • Two major hierarchies in an OO system
    • Is-A
generalization/specialization relationship
Ex: A Rose Is-A Flower
    • Has-A
aggregation/composition relationship
Ex : a Garden object maybe made up of a number of Plant objects.
Garden Has-A Mango_Plant, Garden Has-A Banana_Plant
Aggregation : Pond Has-A Duck, Pond Has-A Tortoise
Composition : Pond Has-A Fish, Car Has-A Carburetor


uml_composition.jpg


  • Advantage of hierarchy/inheritance : code in base class need not be rewritten
in the derived class. The members of base class can be used in the derived class
as well.
  • Disadvantage of multiple inheritance : when two or more superclasses provide
a member with the same name or signature? What will happen? Both will be inherited
in the sub class. Is it possible? No, there should not be two members with the same
name or signature in one class.


Minor elements (Useful, but not essential part of the object model)


Typing (static, dynamic)


  • Type means -> characterization of a set of elements.
  • In OOP, a class is visualized as a type, having properties distinct from any
other type.
  • Typing is the enforcement of the conception, that an object is an instance
of a single class or a type.
  • Objects of different types may not be interchanged, in general, but
  • Can be interchanged only in very restricted manner.


Concurrency


In Operating Systems, concurrency allows performing multiple tasks or processes
simultaneously. When a single process exists in a system, it is said that there is a
single thread of control, but most systems have multiple threads, some active, some
waiting for CPU, some suspended and terminated.
Systems with multiple CPUs inherently permit concurrent threads of control, but
systems running on a single CPU, use appropriate algorithms to give CPU time
slots to the threads so as to enable concurrency. (ex: round robin algorithm)


  • In OOP, there are active and inactive objects.
  • Concurrency is the property that distinguishes an active object from an
inactive object.
  • Concurrency focuses on process abstraction and synchronization.
  • System involving concurrency have many threads of control.
  • The objects synchronize/cooperate with one another.


Persistence


“Persistence is the property of an object through which its existence transcends
time and/or space”


  • An object occupies a memory space and exists for a particular period of time.
  • In some cases the time is small as the evaluation of an expression.
  • In some cases, it is longer than the lifetime of a program. (ex: database)
  • Persistence allows an object to continue existing even after its creator
ceases to exist, also
  • Persistence allows an object will exist by transcending the space its creator
has allocated to it (ex: the object's location moves from the address space in which
it was created)


v. Entity abstraction chooses objects that
A. collect together a general set of actions.
B. can be used by a superior control.
C. are convenient for programming.
D. represent useful components of the problem domain.


Four Types of Abstraction;


  1. Entity Abstraction
An object that represents a useful model of a problem domain or solution domain
entity. It directly mirror the vocabulary of the problem. In an air traffic control system,
some of the entities that would be useful are aircraft, runway, and air corridor.
  1. Action Abstraction
An object that provides a generalised set of operations, all of which perform the
same kind of function. In the case of encryption and decryption of documents,
we can consider an object called scrambler, which embodies a general set of
encryption functions, each of some level of complexity.
  1. Virtual Machine Abstraction
An object that groups operations that are all used by some superior level of control,
or operations that all use some junior-level set of operations. The depiction of the
Unix Operating System as a set of layers, from the kernel to the user file system
is an example of this. Considering a modern computer system as consisting of a
series of layers from the conventional machine level to the microprogramming level
to the machine language level to higher levels is another example of virtual machine
abstraction.
  1. Coincidental Abstraction
An object that packages a set of operations that have no (or maybe a little) relation
to each other. This form of packaging is not considered a good thing. We have an
extreme form of coincidental abstraction when we construct an object called security
and embody within this the methods for performing authentication, calculating the net
present value, etc.


vi. A cohesive module is
A. one that has many dependencies inside it.
B. one that has many methods attached to it.
C. one that has few dependencies inside it.
D. one that allows for quick prototyping.


Issues to be considered when designing classes.


  • Coupling
The strength of connection between classes. (depending on other classes) It is
better to have less coupling, limit coupling but there has to be some trade-off.
Inheritance makes for strong coupling.
  • Cohesion
cohesion refers to the degree to which the elements of a module belong together.
Thus, cohesion measures the strength of relationship between pieces of functionality
within a given module. For example, in highly cohesive systems functionality is
strongly related.
  • Sufficiency
Does the class capture enough of the details of the thing being modeled, to be
useful? The interface has enough to render the interaction of an object meaningful.
  • Completeness
Does the class capture all of the useful behaviour of the thing being modeled to
be re-usable? What about the future users of the class? How much more time takes
to provide completeness?
  • Primitiveness
An operation is primitive if it only works when given access to hidden aspects of
an abstraction. Primitiveness means that you shouldn't make a class unnecessarily
complicated. It is a principle that lets you control a large spectrum of behavior with
just a few operations.


vii. A hierarchy may be defined as
A. a set of high-level components.
B. a measure of the importance of a set of objects.
C. an abstract definition of an object.
D. a ranking or ordering of abstractions.


viii. Object persistence is concerned with
A. the time over which an object exists.
B. objects that cannot be deleted.
C. methods that continue to execute until the correct answer is obtained.
D. the ability of objects to be run on independent threads.


ix. Static typing means that
A. the types of all variables and expressions are not known until runtime.
B. the types of all variables and expressions are known at compilation time.
C. the types of all variables and expressions must be specified by the programmer.
D. the types of all variables and expressions are independent of each other.


Static/Dynamic Typing


Static typing/ static binding/ early binding/ strong typing
The types of all variables and expressions (attributes, operations) are fixed/checked
at the compile time.
Dynamic typing/ late binding/ weak typing
The types of all variables and expressions (attributes, operations) are not
known until runtime.


x. Choose the best description of Object-oriented design:
A. A software design method that decomposes a problem into objects
and describes the logical and physical design of the system.
B. A software design method which uses an object-oriented language such as C++.
C. A software design method that uses objects and methods.
D. A software design method that uses abstraction.


OOT - Object Oriented Technology
Built on an object model which encompasses principles; abstraction,
encapsulation, modularity, hierarchy, typing, concurrency, persistence.
OOT is driven by evolution of programming, from small to large and by
new programming languages.

OOP - Object Oriented Programming
Method of implementation in which programs are organized as cooperative
collections of objects, which are instances of classes, and these classes are
members of a class hierarchy via inheritance relationship.

OOL - Object Oriented Language
Supports objects  (which are data abstractions) to have an interface of
named operations, a hidden local state and an associated type (a class).
Supports types to inherit properties from supertypes.

OOD - Object Oriented Design
Method of design. It is about;
  1. Decomposition or divide a problem into objects
  2. Describe logical and physical design of a system, as well as static
and dynamic models of the system
OOD is based on abstracting (which is an innate activity) : to figure out the
general characteristics of a set of objects to understand them, and classify them.
OOA - Object Oriented Analysis
Initial part/ precursor of OOD. Method of analysis. Examines the requirements
from the perspective (what we can see) of the classes and objects found in the
vocabulary of problem domain.

Question 02


i. An object association is
A. a relationship between objects
B. data encapsulated in an object
C. a method to group objects together
D. a related program


ii. The multiplicity of an object association means:
A. the number of times the association is used in an object oriented design.
B. the number of labels used in the association.
C. that the association involves a numerical value.
D. the number of objects that can be connected to an end-point of the
association.


iii. An association class is
A. the set of all possible associations.
B. a class used to describe an association relationship between two
or more other classes.
C. a class at the end-point of an association link.
D. an abstract class that does not correspond to an entity from the problem
domain.


fig1.png


iv. The diagram in Figure 1 is an example of which type of UML diagram:
A. Class diagram.
B. Component diagram.
C. Package diagram.
D. Use case diagram.


v. The ball port on the diagram in Figure 1 means that the interface is
A. Provided.
B. Required.


vi. In UML, which of the following is not a behaviour diagram:
A. Use case diagram.
B. Activity diagram.
C. Deployment diagram.
D. State machine diagram.


vii. Which of the following does not represent a generalization relationship.
A. relationship between a mammal and a bear.
B. relationship between a father and a child.
C. relationship between an insect and a bee.
D. relationship between an employee and a manager.


viii. Which one of the following is an aggregation relationship.
A. relationship between a finger and a thumb.
B. relationship between a mother and a child.
C. relationship between a bird and an eagle.
D. relationship between a team and the team players.


Associations between objects → Relationships between objects


  • Unidirectional (an arrow directed from owner to owned)
    • A Student has a PencilBox
Student know his/her pencil box, but pencil box don’t know whom it belongs
to.
    • A Customer purchases an Automobile
Customer knows his/her Automobile, but automobile don’t know its’ owner
15782712_1562261717122348_1055299935_n.jpg
15782124_1562261757122344_1084718525_n.jpg
  • Bidirectional (a line between owner and owned)
15820078_1562261787122341_1736679039_n.jpg
15820500_1562261850455668_30283753_n.jpg
  • Roles (roles of the relationship. Ex: “owner”, “owned”)

  • Multiplicity
    • How many objects from one class associate with how many objects in a
                    second class
Multiplicity
Option
Cardinality
0..0
0
Collection must be empty
0..1

No instances or 1 instance
1..1
1
Exactly 1 instance
0..*
*
0 or more instances
1..*

At least 1 instance
5..5
5
Exactly 5 instances
m..n

At least m but no more than n
instances (m , n are integers)

  • Association Class


If an association’s attribute is more complicated to characterize by a single
data type, can use a separate association class.
Ex: Person works for Company each Person-Company association
needs a Position to complete model. Position will be the association class
that helps to characterize the association.

15782691_1562261880455665_881894018_n.jpg
15801542_1562261927122327_739314488_n.jpg


  • Aggregation/Composition (Has-A, Is a part of)


Both are same, (ex: Garden has Mango Plant, Garden has Banana Plant)
but in composition the contained classes (Mango Plant, Banana Plant)
are strongly dependent on the life cycle of the container (Garden).
If container class is destroyed,the contained classes are also vanished.  
In aggregation, not dependent, Plant objects will remain even when the
Garden is destroyed.


A House has a Kitchen, and a Kitchen has a Stove.
15750138_1562261940455659_1807908925_n.jpg






Using Association Class
Has-A
15781996_1562261947122325_1405554528_n.jpg
15782776_1562261960455657_383663163_n.jpg

  • Generalization (Is-A)


The class that holds the generalized characteristics is the base class
(ex: Vehicle)
Classes Airplane, Boat, Car are all kinds of Vehicles, these
classes implement any specialized behaviours.
A Cas is a Vehicle
A Boat is a Vehicle
15782675_1562261980455655_278795833_n.jpg
15782395_1562262023788984_1016018121_n.jpg


  • Multiple Inheritance


class Teacher : public Person, public Employee {
private :
void sleep();
void work();
void teach();
}

About Polymorphism
15749738_1562299037118616_1276225797_n.jpg


Classification


15801047_1562299110451942_1017617186_n.jpg







15730831_1562299137118606_1172684401_n.jpg






15801121_1562299170451936_1499665441_n.jpg








15750063_1562299577118562_1036266006_n.jpg
















You will be given a UML diagram, notations. You should be familiar with all these.


01) Structural Diagrams

  1. Class Diagram
class.png







2. Object Diagram



object.png

















3. Composite Structure Diagram




compo.png












02) Behavioural Diagrams


  1. Use Case Diagramuse case.png


  1. Sequence Diagram
seq.png


  1. State Machine DIagram
state.png







  1. Activity Diagram


act.png


  1. Communication Diagram/Collaboration Diagram
comm.png




  1. Interaction Diagrams
uml-interaction-overview-diagram-elements.png












  1. Timing Diagrams



timing-diagrams-overview.png














03) Implementation Diagrams
  1. Component Diagram
component.png


  1. Deployment Diagram
depl.png


04) Model management Diagrams
  1. Package Diagram
pack.png


  1. Profile Diagram
profile-diagram-overview.png


Vocabulary


Screenshot_2016-12-30_12-32-33.png

Screenshot_2016-12-30_12-32-50.png
Screenshot_2017-01-04_16-23-45.png

No comments:

Post a Comment