I'm learning about interfaces, and I found thread678-812597 to be useful, along with snippets from many other
posts. I've been having a hard time connecting the general statements about what interfaces are used for
with concrete examples (and there are plenty of both...). I think I may have figured something about this out
and was hoping to post that understanding here and get some feedback to fine tune it (or trash it and start
over!)
Here's the view I came up with.
----------------------
Interfaces are very useful in the DESIGN of an app, and the payoff comes in the CODING and the later the MAINTENANCE of the app.
Even if I'm coding an app myself, as a one-person team, there's a lot to remember. If I use interfaces to
describe general relationships between different areas of code, that allows me to work inside those areas of
code one at a time without having to remember (or more likely, constantly go check) what is going on in
some other area.
The thing that has thrown me off in the concrete examples of interfaces is that I could never see the "design
intent" behind them (though this gives me an inkling into the use of what "intention" means in "Foundations of
OOP Using .Net 2.0 Patterns" by Christian Gross").
So what I came to is that you have to, somewhere, define what the methods and attributes inside the
interface are. That is, if you specify a "save" method in an interface, you have to somewhere (such as in
in-line documentation), say, "the 'save' method is used to write objects to the database". So in a sense,
you're writing high level pseudo code (like in a "mock object" from thread678-971775 ) that expresses what
the interface is supposed to enforce (note, "enforce", not "do"). THAT's the "media" that connects the high
level design intent to the actual specification of an interface in code. THAT's what makes an interface mean
something, and how interfaces do their job of "locking" designs into the code. (I think in all the examples I've
seen these descriptions were assumed by context.)
So you could do a lot of design work using interfaces (or conceptual interfaces, before they are coded) describing the relationships between large areas of code (groups of classes, etc.) before starting to work on the details.
So in one sense, the "contract" is between the client and the serving classes, but in another sense the
"contract" is between the designer and the coder (aha, another inkling about what Gross is talking about in
book cited above).
So in a sense, the reason interfaces don't "do" very much in code is that they are mostly DESIGN tools, that
enforce behavior on the coding process. They're not supposed to make bits move, they're supposed to keep
programmers on track.
Then I can see there's another whole layer, which is basically programmer management, that's required to
get the programmer (which would include myself, in my one person project) to use the interfaces in a rigorous
way. So maybe interfaces are "programming process management" tools as well as design tools. That would be the third meaning of the "contract" aspect of interfaces.
Based on this understanding, hopefully the other interesting things about interfaces (which I don't claim to
understand well yet) will start to make more sense.
------------------------------------------------
So, that's what I think I know about interfaces. Any feedback would be appreciated.
Thanks!
posts. I've been having a hard time connecting the general statements about what interfaces are used for
with concrete examples (and there are plenty of both...). I think I may have figured something about this out
and was hoping to post that understanding here and get some feedback to fine tune it (or trash it and start
over!)
Here's the view I came up with.
----------------------
Interfaces are very useful in the DESIGN of an app, and the payoff comes in the CODING and the later the MAINTENANCE of the app.
Even if I'm coding an app myself, as a one-person team, there's a lot to remember. If I use interfaces to
describe general relationships between different areas of code, that allows me to work inside those areas of
code one at a time without having to remember (or more likely, constantly go check) what is going on in
some other area.
The thing that has thrown me off in the concrete examples of interfaces is that I could never see the "design
intent" behind them (though this gives me an inkling into the use of what "intention" means in "Foundations of
OOP Using .Net 2.0 Patterns" by Christian Gross").
So what I came to is that you have to, somewhere, define what the methods and attributes inside the
interface are. That is, if you specify a "save" method in an interface, you have to somewhere (such as in
in-line documentation), say, "the 'save' method is used to write objects to the database". So in a sense,
you're writing high level pseudo code (like in a "mock object" from thread678-971775 ) that expresses what
the interface is supposed to enforce (note, "enforce", not "do"). THAT's the "media" that connects the high
level design intent to the actual specification of an interface in code. THAT's what makes an interface mean
something, and how interfaces do their job of "locking" designs into the code. (I think in all the examples I've
seen these descriptions were assumed by context.)
So you could do a lot of design work using interfaces (or conceptual interfaces, before they are coded) describing the relationships between large areas of code (groups of classes, etc.) before starting to work on the details.
So in one sense, the "contract" is between the client and the serving classes, but in another sense the
"contract" is between the designer and the coder (aha, another inkling about what Gross is talking about in
book cited above).
So in a sense, the reason interfaces don't "do" very much in code is that they are mostly DESIGN tools, that
enforce behavior on the coding process. They're not supposed to make bits move, they're supposed to keep
programmers on track.
Then I can see there's another whole layer, which is basically programmer management, that's required to
get the programmer (which would include myself, in my one person project) to use the interfaces in a rigorous
way. So maybe interfaces are "programming process management" tools as well as design tools. That would be the third meaning of the "contract" aspect of interfaces.
Based on this understanding, hopefully the other interesting things about interfaces (which I don't claim to
understand well yet) will start to make more sense.
------------------------------------------------
So, that's what I think I know about interfaces. Any feedback would be appreciated.
Thanks!