Who killed object oriented design?

6,099 views

Published on

Presentation about Object Oriented Design common anti-patterns, bad habits and how to avoid them.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,099
On SlideShare
0
From Embeds
0
Number of Embeds
4,287
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Who killed object oriented design?

  1. 1. Who killed Object Oriented Design?
  2. 2. Colonel PHP with a lead pipe in the study?
  3. 3. Just look around...
  4. 4. Is OOD making programming more enjoyable?
  5. 5. How many abstract classes have you written lately?
  6. 6. When was the last time that you had a design meeting?
  7. 7. Which one is your favorite LINQ expression?
  8. 8. Why would you use yield or yield return?
  9. 9. Primitive Addiction
  10. 10. Be lazy
  11. 11. Make your life easier
  12. 12. Avoid repetition
  13. 13. Use the source Luke
  14. 14. Creating dates is painful?
  15. 15. DateTime.Parse("...")
  16. 16. new DateTime(y, m, d)
  17. 17. On.Jan(1) On.Aug(3, 2013)
  18. 18. Date arithmetic makes you crazy?
  19. 19. DateTime.Today.AddDays(-3)
  20. 20. 3.Days().Ago
  21. 21. 5.Days().Span
  22. 22. 1.Month().Ago + 5.Days().Span
  23. 23. On.Dec(10) - 2.Months().Span
  24. 24. 2.Months().Before(On.Dec(10))
  25. 25. Date from and to in every method?
  26. 26. What’s missing?
  27. 27. Use a DateRange
  28. 28. new DateRange( !!!!!!On.Jul(1), !!!!!!1.Month().Span)
  29. 29. public class DateRange: !!!!!IEnumerable<DateTime>
  30. 30. var r = new DateRange( !!!!!!!!!!!!!!On.Jul(1), !!!!!!!!!!!!!!On.Sep(3)) r.Select(d => ....)
  31. 31. Generates a sequence of dates
  32. 32. public IEnumerator<DateTime> GetEnumerator() { var counter = this.StartDate; while (counter <= this.EndDate) { yield return counter; counter = counter.AddDays(1); } }
  33. 33. Anemic models
  34. 34. OO mixes behavior and data
  35. 35. Models usually represent data
  36. 36. ...and you realize that there is hardly any behavior on these objects, making them little more than bags of getters and setters... Martin Fowler
  37. 37. Rich vs Anemic
  38. 38. What about SOLID?
  39. 39. Can we justify more classes?
  40. 40. Validators Processors Retrievers Translators Services Builders
  41. 41. class WorkingShift { public Code { get; set; } public Desc { get; set; } }
  42. 42. Night, day or evening... Who’s responsible?
  43. 43. shift.Code == "NIGHT"
  44. 44. class WorkingShift { public Code { get; set; } public Desc { get; set; } public bool IsNight() { ... } }
  45. 45. class Customer { public IsOfDrivingAge { get; } }
  46. 46. How to decide?
  47. 47. Functionality is Complex
  48. 48. Functionality uses multiple models
  49. 49. Interacting with external service
  50. 50. Is not a core concern
  51. 51. Multiple ways of implementation
  52. 52. Some options
  53. 53. Use extensions
  54. 54. public static class CustomerExtensions { public static bool ! ! ! ! IsOfDrivingAge(this Customer ...) }
  55. 55. Decorator
  56. 56. View Model
  57. 57. Service Objects
  58. 58. Form Objects
  59. 59. Repository overpopulation
  60. 60. Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects Martin Fowler
  61. 61. public interface IRepository<T> { IEnumerable<T> All(); void Insert(T entity); void Delete(T entity); }
  62. 62. Custom queries
  63. 63. class CustomerRepository: ! ! ! IRepository<Customer> { // Implementation interface IEnumerable<Customer> FindByAddr(Address ) }
  64. 64. CustomerRepository AddressRepository ChairRepository ...
  65. 65. IQueryable<T>
  66. 66. public interface IRepository<T> { IQueryable<T> All(); void Insert(T entity); void Delete(T entity); }
  67. 67. class CustomerExtensions { public IQueryable<Customer> FindByAddress( this IQueryable<Customer> query, Address address) { query.Where(c => c.Address == address) } }
  68. 68. How many repositories?
  69. 69. Only one generic implementation on top of your favorite ORM
  70. 70. IOC container can instantiate the right one
  71. 71. UnitOfWork can be a factory of repositories
  72. 72. Having an ORM do we really need a repository?
  73. 73. Testing the testable test is tested
  74. 74. A test is about behavior
  75. 75. Not implementation
  76. 76. Writing expectations about implementation makes it brittle
  77. 77. public int ImportantMethod() { var c1 = _dependency1.Calculate(); var c2 = _dependency2.Adjust(c1); return c2 + 10; }
  78. 78. public void ImportantTest() { // arrange .... _dependency1 ! ! ! .Expect(d => d.Calculate()) ! ! ! .Once() ! ! ! .AndReturn(50) _dependency2 ! ! ! .Expect(d => d.Adjust(50)) ! ! ! .Once() ! ! ! .AndReturn(100) // act var actual = sut.ImportantMethod() // assert Assert.That(actual, Is.EqualTo(110)) ! VerifyAllExpectations() }
  79. 79. public int ImportantMethod() { var c1 = _dependency1.Calculate(); var c2 = _dependency2.Adjust(c1); return _dependency2.Adjust(c1) + 10; }
  80. 80. public void ImportantTest() { // arrange .... _dependency1 ! ! ! ! .Stub(d => d.Calculate()) ! ! ! ! .AndReturn(50) _dependency2 ! ! ! ! .Stub(d => d.Adjust(50)) ! ! ! ! .AndReturn(100) // act var actual = sut.ImportantMethod() // assert Assert.That(actual, Is.EqualTo(110)) }
  81. 81. Abstraction subtraction
  82. 82. Exercise in groups
  83. 83. Hospital Domain Model
  84. 84. Versions
  85. 85. What the domain looked like X months ago
  86. 86. DB Driven Development
  87. 87. Model may or may not match the database
  88. 88. Active Record
  89. 89. Transaction Script
  90. 90. Data Mapper
  91. 91. Coding is like Telling a Story
  92. 92. Leave the code cleaner than you found it
  93. 93. Meaning is KING
  94. 94. Don’t code what you don’t need
  95. 95. Know your collections
  96. 96. Let LINQ do the work for you
  97. 97. Use extension methods to mimic a DSL
  98. 98. Discuss design options
  99. 99. Explore F#
  100. 100. Thank you!
  101. 101. http://smartviewapp.com The Smartest tool for lean project management
  102. 102. amir@barylko.com @abarylko http://bit.ly/abarylkoslides
  103. 103. Photo Credit • Under http://creativecommons.org/licenses/by/2.5/ • Joe Cheng, DSC_7820-01, http://flic.kr/p/2Zt2u • Bill Ward, Derek Schin's Trucks 1, http://flic.kr/p/m5L5S • Jeremy Keith, Roast beef, http://flic.kr/p/TKUz • Rob Campbell, Field of daisies, http://flic.kr/p/6QJjU4 • Karin Dalziel, The Thinker, http://flic.kr/p/4UYArc
  104. 104. Photo Credit 2 • Under https://creativecommons.org/licenses/by-sa/2.0/ • Don LaVange, To Irene, https://flic.kr/p/49ihZX • Under http://creativecommons.org/licenses/by-sa/3.0/us/ • Derick Bailey, SOLID Motivational Posters, http://bit.ly/17aVaHg • MGA Roadster 1600 in Chariot Red: http://www.carandclassic.co.uk/car/C414652 • Cone of Uncertainty, http://www.agilenutshell.com/cone_of_uncertainty • Burning Money, http://en.wikipedia.org/wiki/Money_burning#mediaviewer/ File:Burning-money-and-yuanbao-at-the-cemetery-3249.JPG

×