0% found this document useful (0 votes)
8 views11 pages

SDA Lab 05

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

SDA Lab 05

Uploaded by

Muhammad Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

KARACHI INSTITUTE OF ECONOMICS & TECHNOLOGY

College of Engineering

(Software Engineering)

SE3301 – Software Design And Architecture

Semester: Date of Experiment:


Student name: Faculty Signature:
Student ID: Remarks/Comments:

Lab05 Creational Design Pattern-2: Null Object Pattern

PLO1 – Engineering Knowledge C1 – Recall


PLOs PLO3 – Design and Development Bloom’s Taxonomy C3 – Apply
PLO8 – Ethics P2 – Set
LAB TASK PERFORMANCE
Excellent Average Poor
CLO’s Aspects of Assessments (75-100%) (50-75%) (<50%) Marks
Complete understanding of Complete understanding of the Student lacks clear
Recall Recall the concepts of
CLO1
the concepts of C# concepts of C# Programming understanding of concepts of C#
C# Programming Language,
10% Programming Language,OOP Language, OOP and Creational Programming Language, OOP
OOP and Creational Design Design Patterns / less actively
and Creational and Creational
Patterns from theory. Design Patterns / actively participate during lecture. Design Patterns / Unable to read
participates during lecture. and interpret it.
Experimental Validation
Select an appropriate and Correctly select the technique
Correctly select the technique
suitable concept of OOP to to perform Particular task Doesn’t be able to write a logic
CLO6 to perform Particular task
80%
solve and implement real related to Null Object Design and code as per requirement of
related to Null Object Design
world example to validate the Pattern. But code have some the task.
working of Null Object Design Pattern.
minor errors.
Pattern.
Lab Safety Properly handle
CLO7 lab infrastructure/safety Properly handle lab equipment Moderate level lab handling Minor or no safety measurements
10% precautions & obey safety measures. and safety measurements has been considered.

Total Marks: 10
Objective:
1) Make attendee understand the basic concept of Creational Design Pattern
2) Make attendee understand the concept of Null Object Design Pattern
3) Make attendee implement example of .net to create creational design pattern (Null Object)
Tools to be used:
Visual Studio is used to implement .net to create creational design pattern (Singleton).
What is Creational Design Pattern?

The Creational Design Pattern deals with object creation mechanisms; trying to create objects in a manner suitable
to the situation. It focuses on how the objects are created and utilized in an application. Creational Design Pattern
have five categories:

1. Singleton
2. Null Object
3. Abstract Factory
4. Prototype
5. Builder

Null Design Pattern

A null object is also known as a Stub, an Active Nothing or an Active Null. It helps our program logic to get rid of
null checks where ever possible. We all know, that we cannot call methods on a null reference as it results in a
NullReferenceException. The null object pattern provides a non-functional object in place of a null reference and
therefore allows methods to be called on it. Null object design pattern is used to handle the following type of
exceptions:

The Null Object Design pattern is given below:

Null Object Design Pattern


Advantages of Null Design Pattern

● It defines class hierarchies consisting of real objects and null objects.


● Null objects can be used in place of real objects when the object is expected to do nothing.
● The client code is simpler because the conditional complexity is avoided. Clients use real
and null collaborators uniformly.

To implement Null Object Design Pattern, we have to go through the following steps:

Step#01: Create new project of console application.

For old versions:


Step#02: After creation of new class. Add new Interface inside the solution. Inside interface we will define our
methods.

Step#03: Write the methods inside interface class. These methods we are going to use in further implementation.
Step#04: Add new class for mobile data. The class will contain the detail inside methods which has already
named in Interface class.
Step#05: Now inside Mobile Data class, write the methods one by one. In this solution, we are going to write details
of three types of mobile. We will define three classes of three different mobiles which will inherit the methods of
Interface class.
Step#06: After writing the details of three types of mobile, we have to define the null object class. Null object is
defined by using Singleton Design Pattern. Inside NullMobile class, we will define the methods which will do
nothing.

Step#07: Add new class of Mobile Repository. Our repository will return the details of different mobiles.
Step#08: We will use switch case statement in order to show the data of any mobile.
Step#09: Inside main program, create a variable name mobilerepository. By using that variable, we will
get the property GetMobileByName.

Step#10: Now write the mobile name you want to see details of. Check output, it will display the details of
samsung mobile.
Step#11: It’s time to check what null object design pattern will do. It will give nothing in result of nothing.

Lab Task:
1) Implement Null Object Design Pattern in Vehicle Scenario. (Marks: 4)
● Take at least 5 types of vehicles.
● Add 5 methods
● Ask user, which type of vehicle he wants to see.

Home Task:
2) Implement Null Object Design Pattern in a walking Scenario. (Marks: 4)
● Take at least 4 person
● Add 4 methods (up, down, right, left)
● Ask user, which person he wants to see.

You might also like