Can an Interface file contain multiple classes? If so how would one implement this interface file (what specifications do you need to use to specify which class you are using)?

If this is not legal or is a bad programming practice then please explain why.

Thank you,
Arielle

Is this a test question? How many browney points do I get for answering it :)

Is this a test question? How many browney points do I get for answering it :)

No this is not a test question. I am about to start my homework which is write a program that has an exception class and another class and I want to split up the program into application, implementation, and interface files to practice last weeks lesson that taught us about splitting them all up.

For being an awesome guy who responds to all of my questions whenever I post on daniweb I will make you some brownies and mail them to you, but I am not a commander of brownie points and thus cannot give any to you.

>> but I am not a commander of brownie points and thus cannot give any to you.
Awe shucks, and I was hoping to have some brownies tonight :)


>>Can an Interface file contain multiple classes?
Yes. There is no restriction by the compiler or c++ standards on how may you can put into the same file. But for your own sanity (and maybe a better grade) if the classes are large you should separate them into different files.


>>If so how would one implement this interface file (what specifications do you need to use to specify which class you are using)?
It's the same whether the classes are in the same or different files. <class name>::<method name> identifies a specific method within a class.

>>If this is not legal or is a bad programming practice then please explain why
Here are only three reasons. I'm certain other programmers can think up many more reasons.
1) Its just better management to put the classes in different files and it makes the files smaller too.

2) Instead of editing a one-million line file you can edit a file with only a few dozen or so lines.

3) Its easier to find the class you need to work with. If all the classes are in one file you have to search through the entire file to find the class you want -- assuming you put all the methods for each class together. If they are scattered throughout the file then its much much worse.

Thank you for explaining and as soon as we have the stargate up and working i will send those brownies.

One last question, if I separate my classes into two interface files can I use the same implementation file? I am pretty sure I can but not certain...

One last question, if I separate my classes into two interface files can I use the same implementation file? I am pretty sure I can but not certain...

You can, but a better question is should you? Do it however your instructor/professor and/or textbook suggests. In some cases you may not need an implementation file at all -- when everything is inline in the interface file.

You can, but a better question is should you? Do it however your instructor/professor and/or textbook suggests. In some cases you may not need an implementation file at all -- when everything is inline in the interface file.

I am doing this on my own accord, my textbook doesn't say I should even break it up and neither does my professor. I am just doing it for practice.

I thought that the interface file was where you wrote all your function declarations, and the implementation file was for all your function declarations. So I am not understanding what you are saying about:

In some cases you may not need an implementation file at all -- when everything is inline in the interface file.

Please explain.

There are a lot of classes that do not have an implementation file. Take this simple example:

class Hello
{
public:
    Hello() { message = "Hello World";}
    void SayHello() { cout << message << "\n";}
private:
    string message;
};

In the above, lines 4 and 5 are called inline methods because all the code needed to implement the functions are right there in the interfact file. Entire classes can be coded that way.

Ahhh, I see. Thank you very much! The brownies are en route to the rendezvous check point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.