Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IInterface classRef = new ObjectWhatever()
- List myList = new ArrayList(); // programming to the List interface
- ArrayList myList = new ArrayList(); // this is bad
- List myList = new TreeList();
- IInterface classRef = new ObjectWhatever();
- IInterface classRef = container.Resolve<IInterface>();
- public void DoSomethingToAnObject(IInterface whatever) { ... }
- // if I want to add search capabilities to my application and support multiple search
- // engines such as google, yahoo, live, etc.
- interface ISearchProvider
- {
- string Search(string keywords);
- }
- // if I want to support multiple downloads using different protocols
- // HTTP, HTTPS, FTP, FTPS, etc.
- interface IUrlDownload
- {
- void Download(string url)
- }
- // how about an image loader for different kinds of images JPG, GIF, PNG, etc.
- interface IImageLoader
- {
- Bitmap LoadImage(string filename)
- }
- interface IZipCodeRepository
- {
- IList<ZipCode> GetZipCodes(string state);
- }
- PrintZipCodes(IZipCodeRepository zipCodeRepository, string state)
- {
- foreach (ZipCode zipCode in zipCodeRepository.GetZipCodes(state))
- {
- Console.WriteLine(zipCode.ToString());
- }
- }
- char charAt(int index)
- int length()
- CharSequence subSequence(int start, int end)
- String toString()
- interface Airplane{
- parkPlane();
- servicePlane();
- }
- parkPlane(Airplane plane)
- servicePlane(Airplane plane)
- public class Fighter implements Airplane {
- public void parkPlane(){
- // Specific implementations for fighter plane to park
- }
- public void servicePlane(){
- // Specific implementatoins for fighter plane to service.
- }
- }
- public class HighFlyer implements Airplane {
- public void parkPlane(){
- // Specific implementations for HighFlyer plane to park
- }
- public void servicePlane(){
- // specific implementatoins for HighFlyer plane to service.
- }
- }
- public Class ControlPlane{
- AirPlane plane;
- // so much method with AirPlane reference are used here...
- }
- JumboJetPlane // implementing AirPlane interface.
- AirBus // implementing AirPlane interface.
- Dintf bInst = new Bclass();
- // now we could call all Dintf functions implemented (defined) in Bclass.
- Dintf cInst = new Cclass();
- // now we could call all Dintf functions implemented (defined) in Cclass.
- public interface IPricable
- {
- int Price { get; }
- }
- public interface ICar : IPricable
- public abstract class Article
- {
- public int Price { get { return ... } }
- }
- public class Car : Article, ICar
- {
- // Price does not need to be defined here
- }
- //This interface is very flexible and abstract
- addPassenger(Plane seat, Ticket ticket);
- //Boeing is implementation of Plane
- addPassenger(Boeing747 seat, EconomyTicket ticket);
- addPassenger(Cessna, BusinessClass ticket);
- addPassenger(J15, E87687);
Add Comment
Please, Sign In to add comment