Re: difference b/w API and a class
by ikegami (Patriarch) on Oct 21, 2009 at 01:29 UTC
|
There's no relation between the two.
A library's or OS's API refers to the interface used to communicate with that library or OS. An API may rely on the use of objects and classes. Or not.
A class is a data structure whose instances are called objects. Objects encapsulate data in the form of attributes. Methods defined in the class are used to operate on the attributes.
| [reply] |
|
|
Just small addition:
Classes are good for implementation of stateless API.
Objects are good for implementation of API with some states. For instance, the instance of API can keep database connection or authentication credentials according to specified rules.
| [reply] |
Re: difference b/w API and a class
by cdarke (Prior) on Oct 21, 2009 at 08:01 UTC
|
API - Application Program Interface. A general term meaning the way that a program uses a functional library. Usually that is through function/subroutine calls. A Perl API is just an API available for Perl programs to use. The Perl API is the API available for other programs to call and invoke Perl. In this case it means a low-level interface generally called from C.
A Class is a description of a type. It can include an API, in that a program can invoke operations on members of the class (methods on objects), but a Class is much more than just an API. It includes the description of the data. For example, a Class of Car will describe the operations you can do on a car (start the engine, operate the brake, etc.) but also its identity (chassic number, registration number), it's colour, and so on. It may also own objects of other classes: 4 wheels, an engine, gearbox, and so on.
Simplistically, in classic Perl terms, a Class consists of subroutines (the API) and attributes (data). Moose extends this to include other concepts such as roles and delegation. | [reply] |
Re: difference b/w API and a class
by jettero (Monsignor) on Oct 21, 2009 at 01:08 UTC
|
Classes aren't a very Perl concept. Perl thinks of OO as more like namespaces (see also: Moose). So what did you mean by a class? In my mind, the Perl API is XS (which is the darkest magic); but it might also mean, an API for some other package, like GD or XML::Twig or something.
| [reply] |
|
|
Classes aren't a very Perl concept.
At least not in Perl 5. In Perl 6 classes are a very fundamental part of the language.
? In my mind, the Perl API is XS
In my mind, the Perl API is language and its built-in functions and operators as described in the various perldoc documents. One could also call the command line syntax the "Perl API".
But of course XS is also a Perl API, just one that I don't use.
Perl 6 - links to (nearly) everything that is Perl 6.
| [reply] |
|
|
Classes aren't a Perl concept, they're common to all kinds of languages.
And the question wasn't about the perl API, it was a perl API.
I suspect that what the OP wants to hear is that an API is the interface that a vendor documents and provides so that you can write programs to interact with their software. It could be all kinds of different interfaces, such as SOAP or REST, or a bunch of scripts that you run, or a set of libraries that you can use.
Of those, probably the most common is providing a set of libraries with a well-documented interface. If the vendor specifically provides a perl API, then those libraries will almost certainly be in the form of perl modules that you can use in your code, and they might provide an object-oriented (ie, using classes) interface. But the perl interface might instead be procedural, especially if the perl modules provided are just a thin wrapper around C libraries.
| [reply] [d/l] |
Re: difference b/w API and a class
by apl (Monsignor) on Oct 21, 2009 at 11:27 UTC
|
| [reply] |
|
|
nice, somehow I prefer the answer ikegami gave. I advice you to stay away from service related jobs.
| [reply] |