implementation/interface definitions...confused about something.

This is a discussion on implementation/interface definitions...confused about something. within the C++ Programming forums, part of the General Programming Boards category; In the book I'm reading, it makes constant reference to "your implementation" and "the interface" but I don't exactly understand ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    implementation/interface definitions...confused about something.

    In the book I'm reading, it makes constant reference to "your implementation" and "the interface" but I don't exactly understand the terms as they are used. From my understanding the implementation is the compiler and the interface is the actual way you manipulate data in the program. But sometimes the book uses the term very vaguely and it's hard for me to catch the exact meaning as it is in the book. Can someone help me out with this?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,438
    Can you give a few quotes?

    Implementation is pretty straightforward. It's the compiler and linker. But the interface can mean many things, depending on the context.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    The interface is the public member functions of a class. This is the only means the outside world has to interface with your class.

    I believe the implementation typically means the .cpp definitions of the functions within the class.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,666
    Implementation is when you take a data structure and choose how exactly it is going to work. When you answer questions like, what does this class do? What are my needs? -- you are developing an implementation. For instance, the Single Linked List data structure is always the same:
    Code:
    struct node {
       struct node *next;
       int data;
    };
    But there are many implementations, some that are more flexible than others.

    Interface is different. You want your class to be able to work with your program. For instance, a linked list may work, but your users won't be able to see the results. You need to develop an interface. How should we let the user change our objects? How will the user see the object work? etc.

  5. #5
    Registered User
    Join Date
    Jun 2006
    Posts
    30
    You didnt really give enough info. What the chapter is about? Is there any code? From what I know, "interface" of the class is the declarations of its members. Basically, interface tells what your class is capable of doing. "Implementation" is the actual heart of the declarations. It is the code that makes your functions work. For example:
    Code:
    Class myClass {
    public:
         int myInt;
         char *strPtr;
    
         myClass();
         char Function1(char*);
         void Function2(int, double);
    };
    This is the interface of the class. It shows that your class is able to call Function1 and Function2. It also shows that there is a constructor and two variables, which can hold integer and a pointer to char. The implementation of the class might look something like this:
    Code:
    myClass::myClass() : myInt(0), strPtr(0) {}
    
    char myClass::Function1(char *ptr) {
    //Do something here
    }
    
    void myClass::Function2(int num1, double num2) {
    //Do something there
    }
    As you see, Implementation tells how the class achieves whatever it needs to achieve. I'm new to C++ and the whole OOP, so I might be wrong somewhere, or everywhere. The best way would be to search in google, and get the full info on that. Hope this helps!

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> From my understanding the implementation is the compiler
    "Implementation" has different meanings in different contexts. Your understanding is correct for one usage of the word. It has a different meaning when it comes to classes, where there is an interface and an implementation. For that usage the meaning is what is described by the other posts. You just have to look at the context of the statement to understand which meaning is intended.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-24-2009, 02:42 AM
  2. Replies: 7
    Last Post: 11-17-2008, 12:00 PM
  3. Confused
    By (TNT) in forum C# Programming
    Replies: 1
    Last Post: 11-23-2005, 03:49 PM
  4. confused.. in selecting my line of deapth
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-04-2003, 01:21 PM
  5. help writing function definitions
    By jlmac2001 in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2003, 09:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21