Last active
August 29, 2015 14:06
-
-
Save tamizhvendan/4fd1f5ea2b4e28658e81 to your computer and use it in GitHub Desktop.
Verbs - Buried abstraction in OO World
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| List<Student> students = new List<Student>(); | |
| // Populate Students List here | |
| Student[] studentsSortedByName = students.ToArray(); | |
| Array.Sort(studentsSortedByName, new StudentNameComparer()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program1 | |
| { | |
| static void Main(string[] args) | |
| { | |
| List<Student> students = new List<Student>(); | |
| // Populate Students List here | |
| Student[] studentsSortedByAge = students.ToArray(); | |
| Array.Sort(studentsSortedByAge, new StudentAgeComparer()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Program2 | |
| { | |
| static void Main(string[] args) | |
| { | |
| List<Student> students = new List<Student>(); | |
| // Populate Students List here | |
| var studentsSortedByName = Enumerable.OrderBy(students, s => s.Name); | |
| var studentsSortedByAge = Enumerable.OrderBy(students, s => s.Age); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Student | |
| { | |
| public int Age { get; set; } | |
| public string Name { get; set; } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class StudentAgeComparer : IComparer<Student> | |
| { | |
| public int Compare(Student x, Student y) | |
| { | |
| if (x.Age == y.Age) | |
| { | |
| return 0; | |
| } | |
| if (x.Age < y.Age) | |
| { | |
| return -1; | |
| } | |
| return 1; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class StudentNameComparer : IComparer<Student> | |
| { | |
| public int Compare(Student x, Student y) | |
| { | |
| return string.Compare(x.Name, y.Name, StringComparison.CurrentCulture); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment