Ruin0x11 / OpenNefia

(Archived) Moddable engine reimplementation of the Japanese roguelike Elona.
MIT License
115 stars 18 forks source link

Move default aspect function implementations from interfaces to concrete classes #354

Open Ruin0x11 opened 2 years ago

Ruin0x11 commented 2 years ago

I think it would be better to declare the default implementations of aspect functions in the classes implementing the aspects instead of the aspect interfaces. The concern with default functions was reusability, but having them implicitly copied from the interface could be confusing. Instead of having the default functions implicitly copied, writing this code would at least make it clearer where they came from:

local ICharaSandBag = require("mod.elona.api.aspect.ICharaSandBag")
local CharaSandBagAspect = require("mod.elona.api.aspect.CharaSandBagAspect")

local MySandBag = class.class("MySandBag", ICharaSandBag)

function MySandBag:init() 
   -- ...
end

-- Proposed change: document the aspect method reuse explicitly
MySandBag.hang_on_sand_bag = CharaSandBagAspect.hang_on_sand_bag
MySandBag.release_from_sand_bag = CharaSandBagAspect.release_from_sand_bag

Because interface methods have always been copied from the start, this is a only change in convention instead of a change in the way the OOP system works.