Persistent Classes

Person.cs
1/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 2 3namespace Db4objects.Db4odoc.NQCollection 4{ 5 public interface Person 6 { 7 } 8}
Pilot.cs
01/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 02 03namespace Db4objects.Db4odoc.NQCollection 04{ 05 class Pilot : Person 06 { 07 private string _name; 08 private int _points; 09 10 public Pilot(string name, int points) 11 { 12 _name = name; 13 _points = points; 14 } 15 16 public string Name 17 { 18 get 19 { 20 return _name; 21 } 22 set 23 { 24 _name = value; 25 } 26 } 27 28 public int Points 29 { 30 get 31 { 32 return _points; 33 } 34 } 35 36 public override bool Equals(object obj) 37 { 38 if (obj is Pilot) 39 { 40 return (((Pilot)obj).Name.Equals(_name) && 41 ((Pilot)obj).Points == _points); 42 } 43 return false; 44 } 45 46 public override int GetHashCode() 47 { 48 return _name.GetHashCode() + _points; 49 } 50 51 public override string ToString() 52 { 53 return string.Format("{0}/{1}", _name, _points); 54 } 55 } 56}
Trainee.cs
01/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 02 03namespace Db4objects.Db4odoc.NQCollection 04{ 05 class Trainee: Person 06 { 07 private string _name; 08 private Pilot _instructor; 09 10 public Trainee(string name, Pilot pilot) 11 { 12 _name = name; 13 _instructor = pilot; 14 } 15 16 public string Name 17 { 18 get 19 { 20 return _name; 21 } 22 } 23 24 public Pilot Instructor 25 { 26 get 27 { 28 return _instructor; 29 } 30 } 31 32 public override string ToString() 33 { 34 return string.Format("{0}({1})", _name, _instructor); 35 } 36 } 37}
Person.vb
1Namespace Db4objects.Db4odoc.NQCollection 2 3 Public Interface Person 4 End Interface 5 6End Namespace
Pilot.vb
01Namespace Db4objects.Db4odoc.NQCollection 02 03 Class Pilot 04 Implements Person 05 06 Private _name As String 07 Private _points As Integer 08 09 Public Sub New(ByVal name As String, ByVal points As Integer) 10 _name = name 11 _points = points 12 End Sub 13 14 Public Property Name() As String 15 Get 16 Return _name 17 End Get 18 Set(ByVal value As String) 19 _name = value 20 End Set 21 End Property 22 23 Public ReadOnly Property Points() As Integer 24 Get 25 Return _points 26 End Get 27 End Property 28 29 Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean 30 If TypeOf obj Is Pilot Then 31 Return (CType(obj, Pilot).Name.Equals(_name) AndAlso CType(obj, Pilot).Points = _points) 32 End If 33 Return False 34 End Function 35 36 Public Overloads Overrides Function GetHashCode() As Integer 37 Return _name.GetHashCode + _points 38 End Function 39 40 Public Overloads Overrides Function ToString() As String 41 Return String.Format("{0}/{1}", _name, _points) 42 End Function 43 End Class 44End Namespace
Trainee.vb
01Namespace Db4objects.Db4odoc.NQCollection 02 03 Class Trainee 04 Implements Person 05 Private _name As String 06 Private _instructor As Pilot 07 08 Public Sub New(ByVal name As String, ByVal pilot As Pilot) 09 _name = name 10 _instructor = pilot 11 End Sub 12 13 Public ReadOnly Property Name() As String 14 Get 15 Return _name 16 End Get 17 End Property 18 19 Public ReadOnly Property Instructor() As Pilot 20 Get 21 Return _instructor 22 End Get 23 End Property 24 25 Public Overloads Overrides Function ToString() As String 26 Return String.Format("{0}({1})", _name, _instructor) 27 End Function 28 End Class 29End Namespace