Eiffel inheritance and the DRY principle

26 views
Skip to first unread message

Finnian Reilly

unread,
Apr 6, 2018, 10:51:11 AM4/6/18
to Eiffel Users



I have often thought that multiple inheritance in Eiffel can lead to a lot of unnecessary code repetition. I would love to see a change to the Eiffel syntax that would allow me write this:

class
   PAYPAL_PAYMENT

inherit
   KEY_IDENTIFIABLE_STORABLE
      undefine
         new_lio
      redefine
         adjust_field_order
, print_fields, Except_fields, make_default
     
end

   EL_STRING_CONSTANTS
,
   EL_SHARED_EURO_EXCHANGE_RATE_TABLE
, EL_SHARED_CURRENCY_CODES, SHARED_DATABASE,
   PP_SHARED_PAYMENT_PENDING_REASON_ENUM
, PP_SHARED_PAYMENT_STATUS_ENUM,
   CUSTOMER_LINKED
, ADDRESS_LINKED, SUBSCRIPTION_PRICE_CONSTANTS,
   EL_MODULE_LOG
, EL_MODULE_DATE
      undefine
         is_equal
     
end

Instead of what i currently have to write:
class
   PAYPAL_PAYMENT

inherit
   KEY_IDENTIFIABLE_STORABLE
      undefine
         new_lio
      redefine
         adjust_field_order
, print_fields, Except_fields, make_default
     
end

   CUSTOMER_LINKED
      undefine
         is_equal
     
end

   ADDRESS_LINKED
      undefine
         is_equal
     
end

   SUBSCRIPTION_PRICE_CONSTANTS
      undefine
         is_equal
     
end

   EL_MODULE_LOG
      undefine
         is_equal
     
end

   EL_MODULE_DATE
      undefine
         is_equal
     
end

   EL_STRING_CONSTANTS
      undefine
         is_equal
     
end

   EL_SHARED_EURO_EXCHANGE_RATE_TABLE
      undefine
         is_equal
     
end

   EL_SHARED_CURRENCY_CODES
      undefine
         is_equal
     
end

   SHARED_DATABASE
      undefine
         is_equal
     
end

   PP_SHARED_PAYMENT_PENDING_REASON_ENUM
      undefine
         is_equal
     
end

   PP_SHARED_PAYMENT_STATUS_ENUM
      undefine
         is_equal
     
end






Berend de Boer

unread,
Apr 10, 2018, 5:43:16 PM4/10/18
to eiffel...@googlegroups.com
>>>>> "Finnian" == Finnian Reilly <frei...@gmail.com> writes:

Finnian> I have often thought that multiple inheritance in Eiffel
Finnian> can lead to a lot of unnecessary code repetition. I would
Finnian> love to see a change to the Eiffel syntax that would
Finnian> allow me write this

Not a bad idea. But not a use case that pops up often does it?

If you always list the same classes, you could create an ancestor
class doing this for you.

--
All the best,

Berend de Boer

Finnian Reilly

unread,
Apr 11, 2018, 10:17:43 AM4/11/18
to Eiffel Users
Hi Berend


Not a bad idea. But not a use case that pops up often does it?
To answer the question of exactly how often this occurs I created the program UNDEFINE_PATTERN_COUNTER_APP as a sub-application in the utility el_eiffel. (See: UNDEFINE_PATTERN_COUNTER_COMMAND) It takes a source tree manifest file in Pyxis format as an argument and scans all the source files for repetition of a common undefine pattern. It ignores any inheritance clause that has a rename or undefine.  Using a manifest containing a substantial selection of sources I got the following output:

finnian@MacMini ~/Desktop/Eiffel Apps $ el_eiffel -undefine_counter -sources All\ Eiffel\ sources.pyx -define EIFFEL_LOOP=$EIFFEL/library/Eiffel-Loop

Executable: el_eiffel Version: 1.0.9 (37)
Class: UNDEFINE_PATTERN_COUNTER_APP Option: undefine_counter
Description: "Count the number of classes in the source tree manifest that exhibit multiple inheritance of classes
with an identical pattern of feature undefining."


/home/finnian/dev/Eiffel/Electoral/source
/home/finnian/dev/Eiffel/myching-server/source
/home/finnian/dev/Eiffel/My Ching/source
/home/finnian/dev/Eiffel/PF_HP/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/example/eiffel2java/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/example/graphical/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/example/manage-mp3/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/example/net/eros-server/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/example/net/eros-test-clients/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/example/net/source-common
/home/finnian/dev/Eiffel/library/Eiffel-Loop/test/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/tool/eiffel/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/tool/toolkit/source
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/base
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/build
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/graphic
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/language_interface
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/multimedia
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/network
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/persistency
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/runtime
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/testing
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/text
/home/finnian/dev/Eiffel/library/Eiffel-Loop/library/utility

........................................................
Repetition of undefine pattern occurs in 170 out of 2760 classes


This equates to approx 6% of the total number of classes scanned. In my view this is often enough to make it worthwhile amending the Eiffel syntax.

 

If you always list the same classes, you could create an ancestor
class doing this for you.
Obsessionally I have done this but it is not very satisfactory. It makes it cumbersome to check and remove an inherited class if you no longer need it.

best regards
Finnian

Finnian Reilly

unread,
Apr 11, 2018, 10:20:36 AM4/11/18
to Eiffel Users
CORRECTION

It ignores any inheritance clause that has a rename or undefine.
should be
It ignores any inheritance clause that has a rename or redefine.
Reply all
Reply to author
Forward
0 new messages