 |
Exercise 2: Entities, Relationships, and Values
Summary
  | Design an Entity class |
 |   | Implement Set method which allows a property of an entity to be given a value. For the time being, implement words as entities whos IDs are surrounded by single quotes. ex. 'Daniel' |
 |   | Implement a Get method which returns the value of a entity's property |
 |   | Implement an AddRelationship method |
  | Design a Relationship class as a subclass of Entity |
  | Design a Brain class which allows entities to be created via CreateEntity and relationships to be created using CreateEntity. Make the Entity and Relationship classes internal to this class and expose their functionality with the interfaces IEntity and IRelationship. |
 |   | Enforce entity IDs, if specified, to be unique. |
  | Pass the following test case: |
 | [Test] public void Test1() { IEntity is_a = Brain.CreateEntity("is_a"); IEntity has_a = Brain.CreateEntity("has_a");
IEntity Daniel = Brain.CreateEntity("Daniel"); IEntity person = Brain.CreateEntity("person"); Brain.CreateRelationship(Daniel, is_a, person); IEntity first_name = Brain.CreateEntity("first_name"); Brain.CreateRelationship(person, has_a, first_name); IEntity wDaniel = Brain.CreateEntity("'Daniel'"); Daniel.Set(first_name, wDaniel);
Assert.AreEqual("'Daniel'", Daniel.Get(first_name).Id); }} |
|
|
Solution
Click here |
|
 |