Ads

Pages

Wednesday, November 24, 2010

CS-504 Assignment#2 Solution

Q1:Differentiate the following

1) Coupling and Cohesion

2) Object-Oriented and Function-Oriented design

Your solution should be in following format:

Coupling

Cohesion

Coupling between modules/components is their degree of joint interdependence; lower coupling is healthier.

Cohesion of a solitary module/component is the degree to which its responsibilities form a significant unit; higher cohesion is healthier.

v Size: number of relations between routines

v intimacy: the directness of the link among routines

Someone had indistinct reference to decomposability here. Amplification?

v visibility: the prominence of the connection between routines

v flexibility: the ease of changing the connections between routines

How concerning: 'Cohesion is inversely relative to the number of responsibilities a module/part has.'

Coupling explains how dependent a given part of software is on other modules. An extremely coupled system in one in which the events in one module can directly right to use rudiments of another module. A low coupled system in one in which the events of one module can only interrelate with the procedures of another during an interface channel. Highly coupled systems are often characterized by code that is hard to read & maintain (the cause cohesion and coupling are frequently used as opposites).

Cohesion explains how "paying attention" a part of software is. A highly-cohesive system is one in which all procedures in a specified module work jointly towards some end aim. High cohesion is frequently typified by high readability and maintainability.

Object-Oriented Design

Function-Oriented Design

The Basic concept is not the services accessible to the clients of the system

The basic concept is available to clients of the system

The state information survive in the form of data distributed between several objects of the system

The state information is accessible in a federal shared data store.

Group function jointly on the basis of data they work on

Group Functions together if as a group, they constitute a higher level Function

Where OOP orients on objects,

Or as called in C++ classes.

Functional oriented plan familiarize on functions

Object is data with techniques of processing it.

Functions, obtain some data, process it and then revisit result, or do several actions.

Q2

1) Write down any custom built C++ Class which you think is not cohesive (or low cohesive).

Public I Enumerable GetEmployeesFromDb_LowCohesion()

{
// instantiate the links
using(SqlConnection connection = newSqlConnection(ConfigurationManager.ConnectionStrings[CONNECTION_STRING_KEY].ConnectionString))
using(SqlCommand command = new SqlCommand("spGetEmployee", connection)) // instantiate the command

{
command.CommandType = CommandType.StoredProcedure;

// try to open the links
try
{
connection.Open();
}
catch (InvalidOperationException ex)
{
// log exemption
throw;
}
catch (SqlException ex)
{
// log exemption
throw;
}
catch (Exception ex)
{
// log exception
throw;
}

// perform the reader & read the results
using(SqlDataReader reader = command.ExecuteReader())
{
Int32 m_NameOrdinal, m_DeptOrdinal;

// obtain the ordinals
try
{
m_NameOrdinal = reader.GetOrdinal(NAME);
m_DeptOrdinal = reader.GetOrdinal(DEPARTMENT);
}
catch(System.IndexOutOfRangeException ex)
{
// log exemption
throw;
}

Collection result = new Collection();

// interpret the results
while(reader.Read())
{
try
{
Employee emp = new Employee();
emp.Name = reader.IsDBNull(m_NameOrdinal) ? String.Empty: reader.GetString (m_NameOrdinal);
emp.Department = reader.IsDBNull (m_NameOrdinal) ? String.Empty : reader.GetString(m_DeptOrdinal);
result.Add(emp);
}
catch (IndexOutOfRangeException ex)
{
// Log the exemption
throw; // rethrow or handle gracefully here
}
catch (Exception ex)
{
// Log the universal exemption
throw; // rethrow or handle gracefully here
}
}

return result;
}
}
}

No comments:

Post a Comment