[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

question in OOP

i know that interface provide services for classes, so what is the part of your software that should be giving to others developer to use your software as component in their application? is it interface or something else?, i also read that you should give away you API, so what is API compared to interface.
thanks
0
fahadman
Asked:
fahadman
  • 2
  • 2
1 Solution
 
masheikCommented:
Hi,hope this link will help you

http://www.csharphelp.com/archives/archive79.html
0
 
fahadmanAuthor Commented:
thanks, but that didn't answer my question
0
 
Fernando SotoCommented:
Hi fahadman;

To your question, "so what is the part of your software that should be giving to others developer to use your software as component in their application?", If your software is to be used by other developers then you should develop you application as a DLL / Library. Any Interface's that the user of you application will need to use should be placed outside of any class so that it is available to them. Once you have completed the development of the component the DLL / Library is given to any developer wanting to use the Library.

To your question, "i also read that you should give away you API, so what is API compared to interface.", "An application programming interface (API) is a set of routines, data structures, object classes and/or protocols provided by libraries and/or operating system services in order to support the building of applications." From http://en.wikipedia.org/wiki/API. An Interface is a contract which definition a set of subroutines and functions that a user of that interface must implement in there code to comply with the contract.

I hope that helped.

Fernando
0
 
fahadmanAuthor Commented:
good explanation Fernando, so if other want to use my complied software they are going to communicate with my library (DLL files), is this through the interface classes  that i define inside my software or something else. so here is the question, are interfaces used to serve my internal classes or to serve both including the external users?
thanks
0
 
Fernando SotoCommented:
Hi fahadman;

To your question, "are interfaces used to serve my internal classes or to serve both including the external users?"

It can be both. If your component requires a class to implement a interface X and the user did not then you component will fail because it may attempt to execute a function that the user did not implement. The user of an interface can cast his class to the type of the interface it implements. For example see the code snippet that show how this can be used:

Fernando

public interface IX
{
    void DoSomething();
}
 
public class MyYClass : IX
{
    public void DoSomething()
    {
        Console.Print("Class Type MyYClass");
    }
}
 
public class MyZClass : IX
{
    public void DoSomething()
    {
        Console.Print("Class Type MyZClass");
    }
}
 
 
// In another class in code
MyYClass Y = new MyYClass();
MyZClass Z = new MyZClass();
 
// Cast the two different classes to the same interface type that they implement
IX iY = (IX) Y;
IX iZ = (IX) Z;
 
// Create a List that holds objects of type IX
List<IX> listIXs = new List<IX>();
// Add the two classes MyYClass and MyZClass to the list listIXs. This can only be done
// because the two classes implement the IX interface and were cast to IX
listIXs.Add(iY);
listIXs.Add(iZ);

Open in new window

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now