interface vs. implementation uses clause

AbhiJeet
AbhiJeet used Ask the Experts™
on
experts,

what is difference between interface uses clause and implementation uses clause, which is to be used in which scenario?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Interface clause used by all unit function/procedure body and declaration, but implementation clause used by just function/procedure body

Author

Commented:
my question was different, my question was difference between uses clause in interface section and implementation section

interface
uses
 unit1;
implemenation
uses
 unit1;

in which scenario a unit to be referenced in implementation uses clause and in what scenario a unit can be referenced in interface section? ( excluding the reason of circular unit reference)
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Oracle dba
Top Expert 2009
Commented:
first: the difference between interface and implementation

interface

is for defining the headers
  > types
  > procedures and functions
  > constants
  > variables

implementation
*  is for defining all types, constants, variables, procedures and functions  
    which will only be used in this same section of the unit > inside the implementation part itself
* and for all the code of those procedures and functions


a uses clause lists all units which may be referenced by lower defined items

the difference between the 2 uses
interface:
units in this uses clause can be referenced by the whole unit

implementation
units in this uses clause can only be referenced by items in the implementation section itself
Geert GOracle dba
Top Expert 2009

Commented:
oh yeah ...
only items in the interface section are visible  outside of the unit
developmentguruPresident

Commented:
I personally make it a goal to avoid using the implementation uses clause.  The primary reason for using the implementation uses clause, in practical use, is to attempt to get around a circular unit reference.  Just in case you are not aware... a circular unit reference is where Unit A uses Unit B which uses Unit C, which in turn, uses Unit A.  This will produce a compiler error that you have to address before you would be able to compile.  To get into this situation in the first place shows a poor design.  This is a clear indication that the design needs to be redone.  While I have seen this situation, and even gotten around it moving uses into the implementation section, it is not a fix.  At best it is a patch.  If the same design practices continue then the patch will need to be patched again and again until it cannot be fixed using the implementation section.  At this point the whole thing is such a mess that it would have saved a lot of time if it had been corrected the first time the situation was encountered.

Types made available through using another unit will not be available in your own public (interface section) types if they are used from the implementation section.  

I know that you mentioned "excluding the reason of circular unit reference", but since it is the main difference, and not often seen for the poor design trap that it can be, I thought I should go over it.
Ephraim WangoyaSoftware Engineer

Commented:

1. Anything declared in the interface section is global to your application. It can be used in any other unit of your system

2. Anything declared in implementation section is only available to methods in that unit. They can not be used in any other unit
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial