SWDesign-Part I (3)
SWDesign-Part I (3)
Software Design
• Software design is a mechanism to transform user requirements (as
described in software requirements specifications) into some suitable
form, which helps the programmer in software coding and
implementation.
• Effectively managing the complexity will not only reduce the effort
needed for design but can also reduce the scope of introducing errors
during design.
SW Design Principles
Problem Partitioning
• For small problem, we can handle the entire problem at once but for
the significant problem, divide the problems and conquer the problem
it means to divide the problem into smaller pieces so that each piece
can be captured separately.
• For software design, the goal is to divide the problem into manageable
pieces.
Abstraction
• An abstraction is a tool that enables a designer to consider a
component at an abstract level without bothering about the internal
details of the implementation.
• The details of the algorithm to accomplish the functions are not visible
to the user of the function.
• Details of the data elements are not visible to the users of data.
• The independent modules are easier to maintain, test, and reduce error propagation
and can be reused in other programs as well.
• This is because as most data and procedures are hidden from other parts
of the software, inadvertent errors introduced during modifications are
less likely to propagate to different locations within the software.
Coupling and Cohesion
• The measure of interdependencies that exists between two modules of a software program is
called coupling.
• If the degree of dependencies in the program modules is higher, the coupling is said to be tight
coupling (strongly dependent).
• If the degree of dependencies is lesser in the program modules, the coupling is said to be loose.
• Having loosely coupled modules will ensure that each module solves a
definite purpose.
• The data gets passed between the modules through the parameters by making
use of an argument list. While passing the parameters, it must be ensured that
all the parameters must be passed, and no parameter is dropped.
• Data coupling is better than stamp coupling, because the module takes exactly
what it needs, without the need of it knowing the structure of a particular
data structure.
•
Stamp Coupling
• Changing the inner working will lead to the need of changing the
dependent module.
• Violates encapsulation
• What happens if _salary is
changed to __salary in
Employee?
• Hard to maintain
Example Scenario
• Let’s say we have two modules in our application - order and
shipment
• One concept is common in both (i.e. product)
• This means both modules need some logic to handle product
concept
• Possible solutions:
• Create a product module to handle the product concept & and
couple the two modules to it
• Add product concept in both modules
• The second solution implies maintaining the same logic in two
different places.
• If product logic changes we modify both modules
• This is also considered as coupling (logical coupling)
• If product concept never changes there is no problem
• To the contrary, if concept changes frequently, extract to separate
module
• If more other modules use the product concept, extract to
separate module.
• In general, when coupling modules
• Couple modules only using the minimum amount of interfaces
needed.
• Pass only the minimum amount of parameters needed via the
interface(s).
• Pass only data and avoid altering the control flow of our
modules.
Object-Oriented Software Design
• Software design provides a design plan that describes the elements of a
system, how they fit, and work together to fulfill the requirement of the
system.
• The objectives of having a design plan are as follows −
• To negotiate system requirements, and to set expectations with
customers, marketing, and management personnel.
• Act as a blueprint during the development process.
• Guide the implementation tasks, including detailed design, coding,
integration, and testing.
• It comes before the detailed design, coding, integration, and testing and
after the domain analysis, requirements analysis, and risk analysis.
Cells and SW Objects (Alan Kay’s Metaphor)
• Like cells in biological systems, software objects don't know
what goes on inside one another, but they communicate and
work together to perform complex tasks.
• In contrast, monolithic software is like a mechanical clock
containing innumerable gears. Each gear functions
unintelligently and only in relation to other adjacent gears.
• That design is hopelessly flawed. "When you're building gear
clocks, eventually you reach a certain level of complexity and it
falls in on itself,".
Software Objects and Machines
• A software object may be machinelike, but, crafted by a
thoughtful designer, it can be very smart.
• It makes decisions; it does things and knows things.
• It collaborates with potentially many other objects.
• Living in an enclosing machine, it is a whole on one level and a
part on another.
• As with a machine, or a cell, the behaviors of an object are strictly
limited to those that are designed into it.
• Cells and objects follow programmed instructions.
• The dynamic behavior of a software system emerges from
the interactions of many objects—each contributing, each
playing a responsible role.
• All but the simplest of devices, both hardware and software,
are designed from parts. These parts interact according to
someone's plan.
• In a physical machine, these parts touch one another or
communicate through a shared medium. Their interactions
may give way to force, transfer motion, or conduct heat.
Object Machinery
• A software application is constructed from parts (similar to physical
machines).
• These parts—software objects—interact by sending messages to
request information or action from others.
• Throughout its lifetime, each object remains responsible for
responding to a fixed set of requests.
• To fulfill these requests, objects encapsulate scripted responses and
the information that they base them on.
• If an object is designed to remember certain facts, it can use them to
respond differently to future requests.
An Object
• Knows Information
• Performs Services