object oriented programming systems

Post on 15-May-2015

622 Views

Category:

Education

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

Useful for Microsoft.NET training induction programs

TRANSCRIPT

Object Oriented Programming Systems

An Overview

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

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

Programming Techniques

Unstructured Programming

Structured Programming

Modular Programming

Object-Oriented Programming

Modeling

Use Cases

A use case lists a sequence of actions that yields a result that is of value to an actor

Abstract Data Type

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

An OO Program

A circle is a point and a radius

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

An object of circle is a kind of point

If Logo is circle and triangle

Has-A relationship

Relationships between Classes

Three relationships are common among classes :

•Dependency (“uses”)

•Aggregation (“has”)

•Inheritance (“is”)

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

Aggregation

•A class aggregates another if its objects contain objects of the other class

•Aggregation is often informally described as the ‘has-a’ relationship

Inheritance

A class inherits from another if it incorporates the behavior of the other class

Inheritance

Inheritance

Inheritance tree

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....");

}

}

}

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>

</HTML>

CRC Cards

A CRC card is an index card that describes a class, its high-level responsibilities , and its collaborators

Polymorphism

Sample Program – Part 1using System;

public class Control

{

public Control (string data) {Data = data; }

protected string data;

public string Data

{

get { return data ; }

set { data = value; }

}

}

Sample Program – Part 2

interface IValidate

{

bool Validate();

}

class SSN : Control, IValidate

{// Class starts here

const char DELIMITER = '-';

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());

}

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; }

Sample Program – Part 5protected 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

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;

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

COM

Messages

.NET

.NET has 5 intrinsic types :

•Class

•Interface

•Struct

•Enum

•Delegate

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

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

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

The Move from Two-Tier to N-Tier Architecture

Stored Procedures for Business Logic

Two Tier can be messy

Introducing middle tier

The ‘abilities’

Maintainability

Usability

Reliability

Scalability

Security

Integrity

Testability

Performance

Summary

Object Oriented systems are a way of engineering software applications to achieve more consistency and maintainability .

top related