2013-12-20 22 views
4

我一個任務工作,但我無法理解這部分內容:如何理解什麼是需要在這個任務

定義代表布爾GreaterOf(可比OBJ1,可比OBJ2) ( obj1大於obj2)以便根據 比較Comparable對象SizeOf();對於每個結構體,Point,Vector和Triangle定義了一個 私有方法GetSizeOf(Comparable obj1,Comparable obj2)到 爲相應的結構實現代理GreaterOf。定義一個 屬性以獲得GreaterOf的實例對於GetSizeOf()

這裏,可比是有方法聲明的接口:

double SizeOf(); 

我已經實現了三份結構(點,向量,三角)。在這些結構的我已經定義的方法GetSizeOf如下:

對於Point結構:

private bool GetSizeOf (Point obj1, Point obj2) 
    { 
     return obj1.SizeOf() > obj2.SizeOf(); 
    } 

我不明白的是: 定義的屬性來獲得實例GreaterOf for GetSizeOf()。

編輯: 如果這將有助於進一步上這是它是在條件:

定義冒泡(比較[],GreaterOf克)方法進行排序的 陣列的比較的對象,其中,所述代表GreaterOf確定 排序序列(假定的元素可比[]都是 點,矢量或僅三角形)

+0

呃,作業..? – Sean

+5

如果是家庭作業,他會以正確的方式去討論 - 尋求指導,而不是編寫他的代碼。 – Jonesopolis

+0

這不是一項功課。我只是想解決這個問題,但這是我沒有得到的部分。 – user2128702

回答

0

我想你的導師喜歡有一個公共財產,這指向你的私人方法GetSizeOf

public interface Comparable 
    { 
     double SizeOf(); 
    } 

    public delegate bool GreaterOf(Comparable obj1, Comparable obj2); 

    public struct Point 
    { 
     private bool GetSizeOf(Comparable obj1, Comparable obj2) 
     { 
     return obj1.SizeOf() > obj2.SizeOf(); 
     } 

     private GreaterOf _pointGreaterOf; 

     public Point(object a) 
      : this() 
     { 
      var v = a; //it make no sense as is only there to prove the property assignment. 
      PointGreaterOf = GetSizeOf; 
     } 

     public GreaterOf PointGreaterOf 
     { 
      get { return _pointGreaterOf; } 
      set { _pointGreaterOf = value; } 
     } 
    } 

    public struct Trigangle 
    { 
     public GreaterOf TrigangleGreaterOf { get; set; } 

     private bool GetSizeOf(Comparable obj1, Comparable obj2) 
     { 
     return obj1.SizeOf() > obj2.SizeOf(); 
     } 

     public Trigangle(object a) 
      : this() 
     { 
      var v = a;//it make no sense as is only there to prove the property assignment. 
      TrigangleGreaterOf = GetSizeOf; 
     } 
    } 

    public struct Vector 
    { 
     public GreaterOf VectorGreaterOf { get; set; } 

     private bool GetSizeOf(Comparable obj1, Comparable obj2) 
     { 
     return obj1.SizeOf() > obj2.SizeOf(); 
     } 

     public Vector(object a) 
      : this() 
     { 
     var v = a; //it make no sense as is only there to prove the property assignment. 
      VectorGreaterOf = GetSizeOf; 
     } 
    } 
相關問題