comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Best use cases for OOP (resent quoted sorry)
Date: Thu, 28 Aug 2025 17:12:22 +0200	[thread overview]
Message-ID: <108prkk$1dp7v$1@dont-email.me> (raw)
In-Reply-To: <108pq1l$1dp6u$1@dont-email.me>

On 2025-08-28 16:45, Kevin Chadwick wrote:

> I have struggled to find compelling reasons to use tagged types considering
> they affect the size of records and potentially elaboration issues that
> cannot exist without tagged types.

Nothing forces you to use variant sizes or construction hooks. The 
advantage is the you can, if you need it.

> I know some use tagged types just for dot notation but that doesn't really
> move the needle in my mind. I would certainly appreciate it if people could
> share their favourite use cases for tagged types though. Things that are
> perhaps a pain without them or were with Ada 83.

1. The easiest example is network protocols. If you take a look at the 
Simple Components implementation, then the server and client know 
nothing about the actual protocol. They simply read and write chunk of 
data. Upon connection a factory is called which returns an instance of a 
connection object. This type implements HTTP, MQTT, ModBus, LDAP 
whatever. The server/client simply passes data to the object for 
processing. That are dispatching calls.

2. Syntax tree. The nodes of the tree are tagged types. You can nicely 
reuse parts of implementation, e.g. numeric literals etc. You can 
inspect an implementation of Ada expression parser. The parser itself 
knows nothing about Ada. It is the same parser that is used for JSON or XPM.

3. GUI widgets it are practically impossible to have without OO, as you 
need a hierarchy of and an ability to create new widgets using the old 
ones. In AICWL layers of a gauge, oscilloscope, meter are tagged types. 
The instrument is drawn by drawing each layer via a dispatching call.

4. Practically all container types are tagged in order to extend 
functionality but also for generic programming. Consider an ability to 
iterate a container. All iteratable containers form a class. With tagged 
types you can formally define such a class as an interface and inherit 
it in vector, map, set. You can do that with generics too, but that 
would force everything generic.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2025-08-28 15:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-28 14:40 Best use cases for OOP Kevin Chadwick
2025-08-28 14:45 ` Best use cases for OOP (resent quoted sorry) Kevin Chadwick
2025-08-28 15:12   ` Dmitry A. Kazakov [this message]
2025-08-28 18:28   ` Niklas Holsti
2025-08-28 20:23   ` Alex // nytpu
2025-08-29  8:28     ` Dmitry A. Kazakov
2025-08-29  9:14       ` Kevin Chadwick
2025-08-29 10:37         ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox