Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public sealed class Adam : Male
- {
- private static Adam instance;
- private Adam() : base()
- {
- Name = "Adam";
- }
- public static Adam GetInstance()
- {
- if (instance == null)
- {
- instance = new Adam();
- }
- return instance;
- }
- }
- public sealed class Eve : Female
- {
- private static Eve instance;
- private Eve() : base()
- {
- Name = "Eve";
- }
- public static Eve GetInstance(Adam adamInstance)
- {
- if (adamInstance == null) throw new ArgumentNullException();
- if (instance == null)
- {
- instance = new Eve();
- }
- return instance;
- }
- }
- public class Male : Human
- {
- public Male() {}
- public Male(string name, Human mother, Human father)
- {
- if (mother is null) throw new ArgumentNullException();
- if (father is null) throw new ArgumentNullException();
- else
- {
- Name = name;
- Mother = mother;
- Father = father;
- }
- }
- }
- public class Female : Human
- {
- public Female() {}
- public Female(string name, Female mother, Male father)
- {
- if(name=="Eve") throw new ArgumentNullException();
- if (mother is null) throw new ArgumentNullException();
- if (father is null) throw new ArgumentNullException();
- else
- {
- Name = name;
- Mother = mother;
- Father = father;
- }
- }
- }
- public abstract class Human
- {
- public string Name;
- public Human Mother { get; set; }
- public Human Father { get; set; }
- }
- /*
- public void Father_and_mother_are_essential_for_reproduction()
- {
- // There is just 1 way to reproduce
- Assert.AreEqual(1, typeof(Male).GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
- .Where(x => x.IsPublic || x.IsAssembly).Count());
- Assert.AreEqual(1, typeof(Female).GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).
- Where(x => x.IsPublic || x.IsAssembly).Count());
- var adam = Adam.GetInstance();
- var eve = Eve.GetInstance(adam);
- Assert.Throws<ArgumentNullException>(() => new Male("Seth", null, null));
- Assert.Throws<ArgumentNullException>(()=> new Male("Abel", eve, null));
- Assert.Throws<ArgumentNullException>(() => new Male("Seth", null, adam));
- Assert.Throws<ArgumentNullException>(() => new Female("Azura", null, null));
- Assert.Throws<ArgumentNullException>(() => new Female("Awan", eve, null));
- Assert.Throws<ArgumentNullException>(() => new Female("Dina", null, adam));
- Assert.Throws<ArgumentNullException>(() => new Female("Eve", null, null));
- Assert.Throws<ArgumentNullException>(() => new Male("Adam", null, null));
- }
- */
Add Comment
Please, Sign In to add comment