Skip to content

Fixes 2448 i dumper refactor#2460

Merged
erendrake merged 2 commits intoKSP-KOS:developfrom
Dunbaratu:fixes_2448_IDumper_refactor
Mar 19, 2019
Merged

Fixes 2448 i dumper refactor#2460
erendrake merged 2 commits intoKSP-KOS:developfrom
Dunbaratu:fixes_2448_IDumper_refactor

Conversation

@Dunbaratu
Copy link
Member

@Dunbaratu Dunbaratu commented Mar 14, 2019

Fixes #2448 - refactor serialization so geocoords work

Fixes #2448:
This refactor is described better by issue #2448's comments, where
I wrote down a detailed list of what I was doing before I did it.

In a nutshell, previous to this refactor, classes implementing
IDumper had a secret (unenforced) requirement to always have
a default constructor or the serialiazation would fail to
create the object on reading the file/message. That was
because the algorithm used in reading was:

  • (1) - create instance with default constructor.
  • (2) - populate instance using LoadDump() call.

Because interfaces cannot have static things in them, we
couldn't do it properly by saying IDumper is a contract
to create a single factory method that does both (1) and (2)
at once.

This refactor moves the logic to using a new static method
called CreateFromDump() that does do (1) and (2) together,
and the enforcement to confirm that you do indeed have
such a method is done via reflection at runtime since
the compiler cannot do it (C# is one of the almost-OOP
languages that can't handle inheriting static things.)

Once that refactor was done, then Geocoordinates started
working, solving #2448.

This move will (in the next commit) allow
types derived from GenericMessageQueue to be able to
construct new instances of themselves from a static
factory method, which they could not do before
because they needed to pass in a new instance of the
time provider when constructing.  (Now the
GenericMessageQueue constructs its own instance
of the timeprovider from just knowing the timeprovider's
subtype mentioned in the generics.)  This may seem
pointless, but it will be needed to make the next
commit work.
Fixes KSP-KOS#2448:
This refactor is described better by issue KSP-KOS#2448's comments, where
I wrote down a detailed list of what I was doing before I did it.

In a nutshell, previous to this refactor, classes implementing
IDumper had a secret (unenforced) requirement to always have
a default constructor or the serialiazation would fail to
create the object on reading the file/message.  That was
because the algorithm used in reading was:
  1 - create instance with default constructor.
  2 - populate instance using LoadDump() call.
Because interfaces cannot have static things in them, we
couldn't do it properly by saying IDumper is a contract
to create a single factory method that does both (1) and (2)
at once.

This refactor moves the logic to using a new static method
called CreateFromDump() that does do (1) and (2) together,
and the enforcement to confirm that you do indeed have
such a method is done via reflection at runtime since
the compiler cannot do it (C# is one of the almost-OOP
languages that can't handle inheriting static things.)

Once that refactor was done, then Geocoordinates started
working, solving KSP-KOS#2448.
@erendrake erendrake merged commit 3d0c88d into KSP-KOS:develop Mar 19, 2019
Dunbaratu added a commit to Dunbaratu/KOS-1 that referenced this pull request Apr 28, 2019
The word "IKOSTargetable" was accidentally deleted from
the declaration header of class BodyTarget by my PR KSP-KOS#2460.

The SET TARGET command has a check to see if the value being
set is an actual target object or just a string name that
needs to be looked up.  That check was based on seeing if
the value could be cast to IKOSTargetable or not.  When
that was accidentally removed from BodyTarget's header,
it broke that check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants