Component programming
Justin Whear
justin at economicmodeling.com
Wed Jul 31 14:16:20 PDT 2013
On Wed, 31 Jul 2013 12:20:56 +0200, Chris wrote:
> This is only losely related to D, but I don't fully understand the
> separation of component programming and OOP (cf.
> https://en.wikipedia.org/wiki/Component-
based_software_engineering#Differences_from_object-oriented_programming).
> In an OO framwork, the objects are basically components. See also
>
> "Brad Cox of Stepstone largely defined the modern concept of a software
> component.[4] He called them Software ICs and set out to create an
> infrastructure and market for these components by inventing the
> Objective-C programming language." (see link above)
>
> Walter's example
> (http://www.drdobbs.com/architecture-and-design/component-programming-
in-d/240008321)
>
> void main() {
> stdin.byLine(KeepTerminator.yes) // 1 map!(a => a.idup).
> // 2 array. // 3
> sort. // 4 copy(
> // 5
> stdout.lockingTextWriter()); // 6
> }
>
> This is more or less how mature OO programs look like. Ideally each
> class (component) does one thing (however small the class might be) and
> can be used or called to perform this task. All other classes or
> components can live independently. From my experience this is exactly
> what Objective-C does. Rather than subclassing, it uses other classes to
> get a job done.
A few things:
1) The functions used in Walter's example are not methods, they are
generic free functions. The "interfaces" they require are not actual OOP
interfaces, but rather a description of what features the supplied type
must supply.
2) The avoidance of actual objects, interfaces, and methods means that
the costly indirections of OOP are also avoided. The compiler is free to
inline as much of the pipeline as it wishes.
3) Component programming simplifies usage requirements, OOP frameworks
complicate usage requirements (e.g. you must inherit from this class).
If anything, component programming is just functional programming +
templates and some nice syntactic sugar. And a healthy dose of pure
awesome.
More information about the Digitalmars-d
mailing list