ETSI's Bug Tracker - Ext Pack: Object-oriented features (ES 203 790)
View Issue Details
0007866Ext Pack: Object-oriented features (ES 203 790)[All Projects] Generalpublic26-08-2019 14:5709-01-2020 16:03
Jacob Wieland - Spirent 
Jens Grabowski 
normalminorhave not tried
closedfixed 
0007866: Allow nested classes
As it is often more convenient for some implementations, TTCN-3 should allow the definition of nested classes.

A nested class is a class defined inside another class body with access to the containing class's protected and public members.

A nested class shall not define (neither directly nor through inheritance from superclasses) a member with the same name as one of the members of the outer class or its runs on type. If no runs on type is given to the inner class, it inherits it from the outer class. However, it may declare a runs on type which is runs-on compatible with the one from the outer class.

EXAMPLE:

type record of charstring Strings;

type class @abstract StringIterator {
  function @abstract hasNext() return boolean;
  function @abstract next() return charstring;
}


type class StringList {
  var Strings v_strings;
  
  type class Iterator extends StringIterator {
     var integer v_pos := 0;
     
     public function hasNext() return boolean {
       return v_pos < lengthof(v_strings);
     }

     public function next() return charstring {
       v_pos := v_pos + 1;
       return v_strings[v_pos-1];
     }
  }

  function iterator() return Iterator {
    return Iterator.create();
  }
}
No tags attached.
docx CR7866.docx (136,387) 17-12-2019 08:31
http://oldforge.etsi.org/mantis/file_download.php?file_id=3878&type=bug
docx CR7866-2.docx (154,353) 17-12-2019 10:25
http://oldforge.etsi.org/mantis/file_download.php?file_id=3882&type=bug
docx CR7866-3.docx (154,411) 17-12-2019 14:26
http://oldforge.etsi.org/mantis/file_download.php?file_id=3887&type=bug
Issue History
26-08-2019 14:57Jacob Wieland - SpirentNew Issue
27-08-2019 13:39Jacob Wieland - SpirentNote Added: 0015474
27-08-2019 13:39Jacob Wieland - SpirentAssigned To => Jacob Wieland - Spirent
27-08-2019 13:39Jacob Wieland - SpirentStatusnew => assigned
17-12-2019 08:31Jacob Wieland - SpirentFile Added: CR7866.docx
17-12-2019 08:32Jacob Wieland - SpirentNote Added: 0015533
17-12-2019 08:32Jacob Wieland - SpirentAssigned ToJacob Wieland - Spirent => Tomas Urban
17-12-2019 08:32Jacob Wieland - SpirentStatusassigned => confirmed
17-12-2019 10:25Tomas UrbanFile Added: CR7866-2.docx
17-12-2019 10:26Tomas UrbanNote Added: 0015544
17-12-2019 10:26Tomas UrbanAssigned ToTomas Urban => Jacob Wieland - Spirent
17-12-2019 12:44Kristóf SzabadosNote Added: 0015553
17-12-2019 13:28Jacob Wieland - SpirentNote Added: 0015554
17-12-2019 13:29Jacob Wieland - SpirentStatusconfirmed => assigned
17-12-2019 13:29Jacob Wieland - SpirentAssigned ToJacob Wieland - Spirent => Kristóf Szabados
17-12-2019 13:29Jacob Wieland - SpirentStatusassigned => confirmed
17-12-2019 13:36Jacob Wieland - SpirentAssigned ToKristóf Szabados => Tomas Urban
17-12-2019 13:36Jacob Wieland - SpirentStatusconfirmed => assigned
17-12-2019 14:06Kristóf SzabadosNote Added: 0015557
17-12-2019 14:26Tomas UrbanFile Added: CR7866-3.docx
17-12-2019 14:28Tomas UrbanNote Added: 0015561
17-12-2019 14:28Tomas UrbanAssigned ToTomas Urban => Kristóf Szabados
17-12-2019 14:28Tomas UrbanStatusassigned => confirmed
18-12-2019 07:10Kristóf SzabadosAssigned ToKristóf Szabados => Jacob Wieland - Spirent
18-12-2019 07:10Kristóf SzabadosStatusconfirmed => assigned
18-12-2019 07:10Kristóf SzabadosNote Added: 0015563
18-12-2019 07:58Jacob Wieland - SpirentNote Added: 0015566
18-12-2019 07:58Jacob Wieland - SpirentStatusassigned => resolved
18-12-2019 07:58Jacob Wieland - SpirentResolutionopen => fixed
18-12-2019 07:58Jacob Wieland - SpirentAssigned ToJacob Wieland - Spirent => Jens Grabowski
09-01-2020 16:03Jens GrabowskiStatusresolved => closed

Notes
(0015474)
Jacob Wieland - Spirent   
27-08-2019 13:39   
Inner class type : StringList.Iterator

instantiating inner class from outside:

var StringList v_list := StringList.create();
...
var StringList.Iterator v_iterator := v_list.Iterator.create();
(0015533)
Jacob Wieland - Spirent   
17-12-2019 08:32   
please review proposal
(0015544)
Tomas Urban   
17-12-2019 10:26   
I made some minor corrections to the text. Please review the corrections and if you are fine with them, the CR can be marked as resolved.
(0015553)
Kristóf Szabados   
17-12-2019 12:44   
Do I understand correctly right now it is possible to instantiate an object of the nested class, with no object of the containing class?
In which case using member fields of the containing class, does not have any meaning.
(0015554)
Jacob Wieland - Spirent   
17-12-2019 13:28   
No, there is restriction b) which disallows this:

b) Referencing the name of a nested class in a null reference via dotted notation shall cause an error.

How else would you instantiate the object from outside? And if you are inside, the object is 'this'
(0015557)
Kristóf Szabados   
17-12-2019 14:06   
Technically there is no object involved according to the current text, so there can be no null reference:
"The constructor of a nested class may be invoked on a reference composed of the containing and nested class identifier separated by a dot"

In my understanding this talks about class names, not object instances, and class names can not be null ... so the restriction in this setup is not sensible and it is only possible to instantiate a nested class without an object of the containing class.
(0015561)
Tomas Urban   
17-12-2019 14:28   
New resolution uploaded, please review.
(0015563)
Kristóf Szabados   
18-12-2019 07:10   
Looks fine for me, please review.
(0015566)
Jacob Wieland - Spirent   
18-12-2019 07:58   
resolved