comp.lang.ada
 help / color / mirror / Atom feed
* Constructing by classwide type
@ 2017-04-03  1:04 sbelmont700
  2017-04-18 17:37 ` Alejandro R. Mosteo
  0 siblings, 1 reply; 5+ messages in thread
From: sbelmont700 @ 2017-04-03  1:04 UTC (permalink / raw)


Can anyone offer advice on the pros and cons of having constructor functions of extended types return their classwide parent in lieu of the concrete type?  Occasionally I find myself with an abstract parent type that is implemented by a broad number of children, none of which add any new primitive operations or are extended any further, and all of which are intended to be used in the context of their (classwide) parent; in these cases, there seems to be several marginal benefits to returning the parent type, including that nearly all declarations can be put into the body, it forces initialization, the constructor doesn't become a primitive operation, it acts as a kind poor mans 'final' keyword, et al...

None of it is earth-shattering, but apart from not having access to the underlying type (not necessarily a bad thing depending on circumstance), are there other downsides I've yet to discover?

Thanks for any advice

-sb

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Constructing by classwide type
  2017-04-03  1:04 Constructing by classwide type sbelmont700
@ 2017-04-18 17:37 ` Alejandro R. Mosteo
  2017-04-18 18:57   ` Randy Brukardt
  0 siblings, 1 reply; 5+ messages in thread
From: Alejandro R. Mosteo @ 2017-04-18 17:37 UTC (permalink / raw)


On 03/04/17 03:04, sbelmont700@gmail.com wrote:
> Can anyone offer advice on the pros and cons of having constructor functions of extended types return their classwide parent in lieu of the concrete type?  Occasionally I find myself with an abstract parent type that is implemented by a broad number of children, none of which add any new primitive operations or are extended any further, and all of which are intended to be used in the context of their (classwide) parent; in these cases, there seems to be several marginal benefits to returning the parent type, including that nearly all declarations can be put into the body, it forces initialization, the constructor doesn't become a primitive operation, it acts as a kind poor mans 'final' keyword, et al...
>
> None of it is earth-shattering, but apart from not having access to the underlying type (not necessarily a bad thing depending on circumstance), are there other downsides I've yet to discover?
>
> Thanks for any advice

I've been under the same circumstances recently and wondered the same. I 
hope you get some informed answers. Until date, I have noticed no 
drawbacks and all the advantages you mention.

Alex.

>
> -sb
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Constructing by classwide type
  2017-04-18 17:37 ` Alejandro R. Mosteo
@ 2017-04-18 18:57   ` Randy Brukardt
  2017-04-18 19:45     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 5+ messages in thread
From: Randy Brukardt @ 2017-04-18 18:57 UTC (permalink / raw)


"Alejandro R. Mosteo" <alejandro@mosteo.com> wrote in message 
news:od5ins$drj$1@dont-email.me...
...
> I've been under the same circumstances recently and wondered the same. I 
> hope you get some informed answers. Until date, I have noticed no 
> drawbacks and all the advantages you mention.

I don't think there is AN answer. Unless you have to satisfy someone who is 
worshipping a the church of OOP, the best design is the one that works for 
your application, minimizes unnecessary coupling, and makes as many errors 
as possible detectable at compile-time. Use ALL of the features of Ada to 
get there, both OOP and non-OOP features. (Case completeness checks make a 
big difference in being able to modify non-OOP variant record types 
safely -- I find no obvious difference in maintainability between the 
Janus/Ada compiler [designed before OOP was a 'thing'] and the Claw Builder 
[a pure OOP design]. Indeed, incremental development is easier on Janus/Ada 
as usually one doesn't need to write as much code to get it to compile/run.

Anyway, in programming design, there is no one right answer. Ada has a big 
toolbox, it makes sense to use it all.

                                               Randy.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Constructing by classwide type
  2017-04-18 18:57   ` Randy Brukardt
@ 2017-04-18 19:45     ` Dmitry A. Kazakov
  2017-04-19 20:45       ` Randy Brukardt
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2017-04-18 19:45 UTC (permalink / raw)


On 2017-04-18 20:57, Randy Brukardt wrote:
> "Alejandro R. Mosteo" <alejandro@mosteo.com> wrote in message
> news:od5ins$drj$1@dont-email.me...
> ...
>> I've been under the same circumstances recently and wondered the same. I
>> hope you get some informed answers. Until date, I have noticed no
>> drawbacks and all the advantages you mention.
>
> I don't think there is AN answer. Unless you have to satisfy someone who is
> worshipping a the church of OOP, the best design is the one that works for
> your application, minimizes unnecessary coupling, and makes as many errors
> as possible detectable at compile-time.

Yes, but in some cases one can prove more or less formally that the 
design might not work. So it is not always arbitrary.

Regarding the question it seems overloading vs. overriding / factory vs. 
constructing functions, not really exactly same use case.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Constructing by classwide type
  2017-04-18 19:45     ` Dmitry A. Kazakov
@ 2017-04-19 20:45       ` Randy Brukardt
  0 siblings, 0 replies; 5+ messages in thread
From: Randy Brukardt @ 2017-04-19 20:45 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:od5qd0$10nc$1@gioia.aioe.org...
> On 2017-04-18 20:57, Randy Brukardt wrote:
>> "Alejandro R. Mosteo" <alejandro@mosteo.com> wrote in message
>> news:od5ins$drj$1@dont-email.me...
>> ...
>>> I've been under the same circumstances recently and wondered the same. I
>>> hope you get some informed answers. Until date, I have noticed no
>>> drawbacks and all the advantages you mention.
>>
>> I don't think there is AN answer. Unless you have to satisfy someone who 
>> is
>> worshipping a the church of OOP, the best design is the one that works 
>> for
>> your application, minimizes unnecessary coupling, and makes as many 
>> errors
>> as possible detectable at compile-time.
>
> Yes, but in some cases one can prove more or less formally that the design 
> might not work. So it is not always arbitrary.
>
> Regarding the question it seems overloading vs. overriding / factory vs. 
> constructing functions, not really exactly same use case.

Which was really my point: the design should get organized according to the 
use, not according to some religion which is then bent to the use. In my 
experience, the factory constructor use case doesn't come up much - most of 
the time you know what object you need (and want to create it statically).

                                        Randy.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-19 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-03  1:04 Constructing by classwide type sbelmont700
2017-04-18 17:37 ` Alejandro R. Mosteo
2017-04-18 18:57   ` Randy Brukardt
2017-04-18 19:45     ` Dmitry A. Kazakov
2017-04-19 20:45       ` Randy Brukardt

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