2. Object Oriented Analysis And
Design
•Software development process consists of analysis,
design, and implementation phases
•The goal of the analysis phase is a complete description
of what the software product should do
•The goal of object-oriented design is the identification of
classes, their responsibilities, and the relationships among
them
•The goal of the implementation phase is the
programming, testing, and deployment of the software
product
3. Why OOPS ?
• To modularize software development , just like any other
engineering discipline
•To make software projects more manageable and
predictable
•For better maintainability, since software maintenance
costs were more than the development costs.
•For more reuse of code and to prevent the ‘reinvention of
the wheel’ every time
11. OOPS
• A class specifies objects with the same behavior
•An instance of a class is an object that belongs to the given
class
•Class names should be nouns in the singular form
•To discover responsibilities , look for verbs in the problem
description.
•A responsibility must belong to exactly one class
14. Class and Object concept
An object is characterized by its state, behavior, and identity
• The collection of all information held by an object is its state
•The behavior of an object is defined by the operations or
methods that an object supports
•The unique reference (or name) of an object is its identity
19. Dependency
• A class depends on another class if it manipulates objects of the
other class in any way.
•If a class can carry out all its tasks without being aware that the
other class even exists, then it doesn’t use that class.
•For example, if there is a Message class which uses the
System.Print class, then the Message class is dependant , or
coupled with the System.Print class
20. Aggregation
•A class aggregates another if its objects contain objects of
the other class
•Aggregation is often informally described as the ‘has-a’
relationship
25. ASP.NET component
using System;
using System.Web.UI;
namespace MSPress.ServerControls
{
public class SimpleControl : Control
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write("I don't do anything useful. ");
writer.Write("but at least i'm a control....");
}
}
}
26. Re-using the component
<%@ Page language="C#" %>
<%@ Register TagPrefix="msp" NameSpace="MSPress.ServerControls"
Assembly="SimpleControl.cs" %>
<HTML>
<body>
<br>
Here is the output from our first custom control
<br>
<msp:SimpleControl id="simple1" runat="server" />
<br>
</body>
27. CRC Cards
A CRC card is an index card that describes a class, its high-
level responsibilities , and its collaborators
29. Sample Program – Part 1
using System;
public class Control
{
public Control (string data) {Data = data; }
protected string data;
public string Data
{
get { return data ; }
set { data = value; }
}
}
30. Sample Program – Part 2
interface IValidate
{
bool Validate();
}
class SSN : Control, IValidate
{// Class starts here
const char DELIMITER = '-';
31. Sample Program – Part 3
public SSN(string val) : base (val) {}
public bool Validate()
{
Console.WriteLine("[SSN.Validate] : Validating
'{0}'", data);
return (11 == data.Length) && (CorrectFormat());
}
32. Sample Program – Part 4
protected bool CorrectFormat()
{bool correctFormat = true;
for (int i = 0; (correctFormat && i < data.Length);
i++)
{
correctFormat =((IsDelimiterPosition(i) && data[i]
== DELIMITER)|| (IsNumberPosition(i)&&
char.IsNumber(data[i])));
}
return correctFormat; }
33. Sample Program – Part 5
protected bool IsDelimiterPosition(int i)
{
return (i==3 | i==6);
}
protected bool IsNumberPosition (int i)
{
return (i !=3 && i != 6);
}
} //class SSN : Control, IValidate ends here
34. Sample Program – Part 6
class InterfacesApp
{ //Main class starts here
public static void Main(string[] args)
{
string data = "";
if (0 < args.GetLength(0))
data = args[0];
SSN ssn = new SSN(data);
IValidate val = (IValidate)ssn;
35. Sample Program – Part 7
Console.WriteLine("[Main] Calling SSN.Validate");
bool success = val.Validate();
Console.WriteLine("[Main] The validation of
" +
"SSN '{0}' was {1}successful",
ssn.Data,
(true == success ? "" : "NOT "));
}
} //Main class ends here
39. A simple example of .NET
delegate – Part 1
' Our delegate type can point to any method
' taking two integers and returning an integer.
Public Delegate Function BinaryOp(ByVal x As Integer,
ByVal y As Integer) As Integer
40. A simple example of .NET
delegate – Part 2
'This class defines the methods that will be 'pointed to' by the delegate.
Public Class SimpleMath
Public Shared Function Add(ByVal x As Integer, ByVal y As Integer) As
Integer
Return x + y
End Function
Public Shared Function Subtract(ByVal x As Integer, ByVal y As Integer)
As Integer
Return x - y
End Function
End Class
41. A simple example of .NET
delegate – Part 3
Module Program
Sub Main()
Console.WriteLine("****** Simple Delegate Example*******")
'Make a delegate object and add method to invocation
'list using the AddressOf keyword.
Dim b As BinaryOp = New BinaryOp(AddressOf
SimpleMath.Add)
'Invoke the method 'pointed to'
Console.WriteLine("10 + 10 is {0}", b(10, 10))
Console.ReadLine()
End Sub
End Module