object oriented programming systems

47
Object Oriented Programming Systems An Overview

Upload: rchakra

Post on 15-May-2015

621 views

Category:

Education


4 download

DESCRIPTION

Useful for Microsoft.NET training induction programs

TRANSCRIPT

Page 1: Object oriented programming systems

Object Oriented Programming Systems

An Overview

Page 2: Object oriented programming systems

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

Page 3: Object oriented programming systems

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

Page 4: Object oriented programming systems

Programming Techniques

Unstructured Programming

Page 5: Object oriented programming systems

Structured Programming

Page 6: Object oriented programming systems

Modular Programming

Page 7: Object oriented programming systems

Object-Oriented Programming

Page 8: Object oriented programming systems

Modeling

Page 9: Object oriented programming systems

Use Cases

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

Page 10: Object oriented programming systems

Abstract Data Type

Page 11: Object oriented programming systems

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

Page 12: Object oriented programming systems

An OO Program

Page 13: Object oriented programming systems

A circle is a point and a radius

Page 14: Object oriented programming systems

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

Page 15: Object oriented programming systems

An object of circle is a kind of point

Page 16: Object oriented programming systems

If Logo is circle and triangle

Page 17: Object oriented programming systems

Has-A relationship

Page 18: Object oriented programming systems

Relationships between Classes

Three relationships are common among classes :

•Dependency (“uses”)

•Aggregation (“has”)

•Inheritance (“is”)

Page 19: Object oriented programming systems

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

Page 20: Object oriented programming systems

Aggregation

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

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

Page 21: Object oriented programming systems

Inheritance

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

Page 22: Object oriented programming systems

Inheritance

Page 23: Object oriented programming systems

Inheritance

Page 24: Object oriented programming systems

Inheritance tree

Page 25: Object oriented programming systems

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

}

}

}

Page 26: Object oriented programming systems

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>

Page 27: Object oriented programming systems

CRC Cards

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

Page 28: Object oriented programming systems

Polymorphism

Page 29: Object oriented programming systems

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

}

}

Page 30: Object oriented programming systems

Sample Program – Part 2

interface IValidate

{

bool Validate();

}

class SSN : Control, IValidate

{// Class starts here

const char DELIMITER = '-';

Page 31: Object oriented programming systems

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

}

Page 32: Object oriented programming systems

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

Page 33: Object oriented programming systems

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

Page 34: Object oriented programming systems

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;

Page 35: Object oriented programming systems

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

Page 36: Object oriented programming systems

COM

Page 37: Object oriented programming systems

Messages

Page 38: Object oriented programming systems

.NET

.NET has 5 intrinsic types :

•Class

•Interface

•Struct

•Enum

•Delegate

Page 39: Object oriented programming systems

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

Page 40: Object oriented programming systems

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

Page 41: Object oriented programming systems

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

Page 42: Object oriented programming systems

The Move from Two-Tier to N-Tier Architecture

Page 43: Object oriented programming systems

Stored Procedures for Business Logic

Page 44: Object oriented programming systems

Two Tier can be messy

Page 45: Object oriented programming systems

Introducing middle tier

Page 46: Object oriented programming systems

The ‘abilities’

Maintainability

Usability

Reliability

Scalability

Security

Integrity

Testability

Performance

Page 47: Object oriented programming systems

Summary

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