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


Tutorials



WHEN AND LIKE



There are two ways to implement object-oriented inheritance in e: like inheritance and when inheritance



Like



Like inheritance is the classical, single inheritance familiar to users of all object-oriented languages and is specified with the like clause in new struct definitions.




EXAMPLE:
<'

struct exam {
from_exam() is {
out ( "This is BASE" );
};

};

struct e_exam like exam{
from_exam() is only {
out( "This is EXTENDED" );

};

};

extend sys {
exam : exam;
e_exam : e_exam;
run() is also {
exam.from_exam();
e_exam.from_exam();
};

};
'>


RESULT:

This is BASE
This is EXTENDED



When



When inheritance is a concept unique to e and is specified by defining subtypes with when struct members. When inheritance provides the following advantages compared to like inheritance:
-Ability to have explicit reference to the when fields
-Ability to have multiple, orthogonal subtypes
-Ability to extend the struct later




EXAMPLE:when
<'
type pack_kind :[long, short];
struct packet {
kind: pack_kind;
when long packet {
a: int;
};
check_my_type() is {
if me is a long packet (l) {
print l;
};
if me is not a long packet {
print kind;
};
};
};
extend sys {
p:packet;
run() is also {
p.check_my_type();
}
};
'>
RESULT

l = packet-@0: packet
--------------------------------------------------@test
0 kind: long
1 long'a: 2129590818


Index
Introduction
E Basics
Data Types
Operators
Struct
Units
List
Methods
Concurrency Actions
Constraints
Extend
When And Like
Events
Temporal Expressions
Temporal Operators 1
Temporal Operators 2
Synchronizing With The Simulator
Wait And Sync
Physical Virual Feilds
Packing N Unpacking
Pre Run N On The Fly
Coverage
Commands
Extendable Methods
Non Extendable Methods
And Gate Evc

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