xmlsquad / gsheet-to-xml

Given the url of a Google Sheet, this Symfony Console command fetches the Google Sheet and outputs it in the form of Xml.
Apache License 2.0
3 stars 1 forks source link

Abstract the InventoryFactory to allow it to be extended to other models. #23

Closed forikal-uk closed 6 years ago

forikal-uk commented 6 years ago

Goal

[See title]

Why

[See title]

How

forikal-uk commented 6 years ago

Rename:

make()

To:

createDomainGSheetObject

and then introduce a Template method according to the Template Pattern.

forikal-uk commented 6 years ago

I was heading towards the Template Pattern.

But, after getting to know the InventoryFactory class a bit more I have had a breakthrough in understanding and realise that it is probably better use an Interface rather than an abstraction.

This gives greater flexibility to the user-land developer. Abstract models tend to be painful because people like freedom to design models without abstracts directing their way.

forikal-uk commented 6 years ago

Where do i put the Interface?

I am not so familiar with Symfony best practice.

I am just going to put it into the Model folder and it will be separated out when the concrete model is separated from the library.

forikal-uk commented 6 years ago

I wonder how Return Type Declarations relate to method Interfaces?

It seems the concrete implementation can specify a return type while the Interface method specifies no return type. So, it seems to work.

Also, the docs kind of support that (albeit when talking about abstract methods):

http://php.net/manual/en/functions.returning-values.php#functions.returning-values.type-declaration

Note:

When overriding a parent method, the child's method must match any return type declaration on the parent. If the parent doesn't define a return type, then the child method may do so.

I have found this article.

Let's see what happens when we set strict in the bootstrap.

<?php
declare(strict_types=1);

Result: Even in strict mode you can implement an Interface's method and set a return type when the return type is not set on the Interface's method definition.

That's interesting to know.

forikal-uk commented 6 years ago

Let's go through and replace mentions of the interface instead of the concrete Inventory factory, where possible.