πŸ“¦ Packages


Packages are the way to encapsulate concepts into objects and library modules.

One of the most important things a package can do is create an isolated environment for the type. All his processes can be encapsulated inside the black box of the package, as well as helpful internal variables.

As packages are defined in their body files, and isolated from the environment by definition, we have to make an interface file to tell the public user what the package promises to do.

A great metaphor is that a package is like a business.

There are many details that the client should not see (or our competitors in the market), like the making of the product, negotiations with suppliers, accounting... That happens in the body of the business (package).

In spite of all this complexities, the client needs only to head to the store and pick the products (types and functions) or services (procedures) that they desire from the selection that we offer.

The store is our interface.

Interface

my_package.ads


Body

my_package.adb


Note: Object Oriented Programming? This is it!

Packages accomplish what other Object Oriented Programming languages do within classes, an utterly nonsensical term that mixes packages and types into one concept, breaking the one purpose rule they are theoretically trying to implement.

If you never heard of Object Oriented Programming, it's just a smart use of packages. Don't worry about it, as you will learn all the "OOP" tricks and ticks as we go along.

As a personal anecdote, in my first job as a developer I joined the company thinking I knew zero oop. My only two languages were C and Ada at the time. Thanks to my fluency in Ada I was able to write "oop" code in a weeks time. Not bragging, just that oop is only an (over)using of multiple features I was already familiar with. Main of them, library packages and structures.

Also mention that OOP is (finally) loosing hype, so it seems, and getting substituted by (traditional) procedural , functional, and also contractual programming. Ada supports all styles, so we'll check them all eventually. Contract Oriented Programming is my personal favorite atm.

OOP is, nonetheless, sometimes the smartest way of programming, in the right context.