|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



NULL



The Null is perhaps the most "intelligent" pattern of all. It knows exactly what to do all the time, every time. Its does nothing. The Null is somewhat difficult to describe, since it resides in an abstract hierarchy tree, having no particular place at all, but occupying many roles. It is somewhat like the mathematical concept of zero: it is a placeholder, but is in itself nothing, and has no value. Null Object is a behavioral pattern designed to act as a default value of an object in most OOPs tools. These references need to be checked to ensure they are not null before invoking any methods, because one can't invoke anything on a null reference; this tends to make code less readable. If you forgot to creat an object ane passed it to method, where the method has some operation on the object, the simulation fails. So , If the method is expecting an object , then check weathe the object is created or not else take nessesary action. The advantage of this approach over a working default implementation is that a Null Object is very predictable and has no side effects.



EXAMPLE
class B;

task printf();
$display(" Hi ");
endtask
endclass

program main;
initial
begin
B b;
print(b);
end
endprogram

task print(B b);
if(b == null)
$display(" b Object is not created ");
else
b.printf();
endtask


RESULT:

b Object is not created

Index
Introduction
Class
Object
This
Inheritance
Encapsulation
Polymorphism
Abstract Classes
Parameterised Class
Nested Classes
Constant
Static
Casting
Copy
Scope Resolution Operator
Null
External Declaration
Classes And Structures
Typedef Class
Pure
Other Oops Features
Misc

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer