Guest User

Untitled

a guest
Sep 30th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. IInterface classRef = new ObjectWhatever()
  2.  
  3. List myList = new ArrayList(); // programming to the List interface
  4.  
  5. ArrayList myList = new ArrayList(); // this is bad
  6.  
  7. List myList = new TreeList();
  8.  
  9. IInterface classRef = new ObjectWhatever();
  10.  
  11. IInterface classRef = container.Resolve<IInterface>();
  12.  
  13. public void DoSomethingToAnObject(IInterface whatever) { ... }
  14.  
  15. // if I want to add search capabilities to my application and support multiple search
  16. // engines such as google, yahoo, live, etc.
  17.  
  18. interface ISearchProvider
  19. {
  20. string Search(string keywords);
  21. }
  22.  
  23. // if I want to support multiple downloads using different protocols
  24. // HTTP, HTTPS, FTP, FTPS, etc.
  25. interface IUrlDownload
  26. {
  27. void Download(string url)
  28. }
  29.  
  30. // how about an image loader for different kinds of images JPG, GIF, PNG, etc.
  31. interface IImageLoader
  32. {
  33. Bitmap LoadImage(string filename)
  34. }
  35.  
  36. interface IZipCodeRepository
  37. {
  38. IList<ZipCode> GetZipCodes(string state);
  39. }
  40.  
  41. PrintZipCodes(IZipCodeRepository zipCodeRepository, string state)
  42. {
  43. foreach (ZipCode zipCode in zipCodeRepository.GetZipCodes(state))
  44. {
  45. Console.WriteLine(zipCode.ToString());
  46. }
  47. }
  48.  
  49. char charAt(int index)
  50. int length()
  51. CharSequence subSequence(int start, int end)
  52. String toString()
  53.  
  54. interface Airplane{
  55. parkPlane();
  56. servicePlane();
  57. }
  58.  
  59. parkPlane(Airplane plane)
  60.  
  61. servicePlane(Airplane plane)
  62.  
  63. public class Fighter implements Airplane {
  64.  
  65. public void parkPlane(){
  66. // Specific implementations for fighter plane to park
  67. }
  68. public void servicePlane(){
  69. // Specific implementatoins for fighter plane to service.
  70. }
  71. }
  72.  
  73. public class HighFlyer implements Airplane {
  74.  
  75. public void parkPlane(){
  76. // Specific implementations for HighFlyer plane to park
  77. }
  78.  
  79. public void servicePlane(){
  80. // specific implementatoins for HighFlyer plane to service.
  81. }
  82. }
  83.  
  84. public Class ControlPlane{
  85. AirPlane plane;
  86. // so much method with AirPlane reference are used here...
  87. }
  88.  
  89. JumboJetPlane // implementing AirPlane interface.
  90. AirBus // implementing AirPlane interface.
  91.  
  92. Dintf bInst = new Bclass();
  93. // now we could call all Dintf functions implemented (defined) in Bclass.
  94.  
  95. Dintf cInst = new Cclass();
  96. // now we could call all Dintf functions implemented (defined) in Cclass.
  97.  
  98. public interface IPricable
  99. {
  100. int Price { get; }
  101. }
  102.  
  103. public interface ICar : IPricable
  104.  
  105. public abstract class Article
  106. {
  107. public int Price { get { return ... } }
  108. }
  109.  
  110. public class Car : Article, ICar
  111. {
  112. // Price does not need to be defined here
  113. }
  114.  
  115. //This interface is very flexible and abstract
  116. addPassenger(Plane seat, Ticket ticket);
  117.  
  118. //Boeing is implementation of Plane
  119. addPassenger(Boeing747 seat, EconomyTicket ticket);
  120. addPassenger(Cessna, BusinessClass ticket);
  121.  
  122.  
  123. addPassenger(J15, E87687);
Add Comment
Please, Sign In to add comment