Nov 28, 2018 23:51
and even though you could argue that it is more complicated than Option1 (which I don't agree with) it still leaves me with concrete types.
Nov 28, 2018 23:50
it doesn't break encapsulation, it leaves me with concrete types (which I like)
Nov 28, 2018 23:50
But you haven't told me why you hate the pastebin option so much
Nov 28, 2018 23:48
which I do, and have to when I have anything that is a class implementing an interface
Nov 28, 2018 23:47
no, it doesn't. But you can tell JSON.Net to also output the object type :)
Nov 28, 2018 23:47
I know whether it is a DomainJoin or a NetworkJoin because the GetType() tells me so
Nov 28, 2018 23:46
I like the fact that when I look at my serialized data I have a concrete type
Nov 28, 2018 23:44
I expected that when I ordered something from Amazon 2 days ago and they told me it would arrive on the 29th that it would be here today. Turns out it will be here on Friday instead :P
Nov 28, 2018 23:44
What you expect and what happens are two different things.
Nov 28, 2018 23:43
the point is you end up with something that's not concrete. You have an object that could either signify this or that
Nov 28, 2018 23:42
but again that's an assumption. It might even go "hey, let me try to do a join based on JoinType but if I find that I don't have enough information to perform that type of join, then let me try to see if at least I can do the other type of join"
Nov 28, 2018 23:41
I mean it's assumed that JoinType will be what determines the Join
Nov 28, 2018 23:40
because what's NOT explicit is what will happen when you specify all values and set JoinType to Workgroup.
Nov 28, 2018 23:40
yeah, it's 00:39 here...
Nov 28, 2018 23:39
you can't look at a POCO like that and tell me you think it's properly created. That it can't be improved
Nov 28, 2018 23:38
and that's ... even worse imho
Nov 28, 2018 23:38
so now Option1 would end up being a POCO with JoinType, DomainName, WorkgroupName, DomainUsername, DomainPassword
Nov 28, 2018 23:38
right, but in Option1 (which is what we were discussing) there is just 1 Name property
Nov 28, 2018 23:37
Agree, serialization doesn't care
Nov 28, 2018 23:36
But I still don't see how the pastebin example breaks encapsulation
Nov 28, 2018 23:35
I can make it only display a value if JoinType == JoinType.Domain/Workgroup
Nov 28, 2018 23:35
because I have a single property associated with two controls
Nov 28, 2018 23:35
my workgroup TextBox will now show "MyDomain.local"
Nov 28, 2018 23:34
if I replace "MyWorkgroup" with "MyDomain.local" and click workgroup again
Nov 28, 2018 23:34
if I click the RadioButton for domain then the workgroup TextBox will become empty and the domain TextBox will read "MyWorkgroup"
Nov 28, 2018 23:33
my UI has 2 TextBoxes and the one for the domain is empty (using a conditional setter in XAML) and the one for the Workgroup shows "MyWorkgroup"
Nov 28, 2018 23:32
When POCO.Name = "MyWorkgroup" and POCO.JoinType = JoinType.Workgroup ...
Nov 28, 2018 23:32
single POCO?
Nov 28, 2018 23:32
the second issue? Notice that on the picture there's 1 TextBox for Workgroup.Name and another for Domain.Name
Nov 28, 2018 23:31
That's the first issue ...
Nov 28, 2018 23:31
Sure it should be the JoinType that determines what join is done, but you don't know that for sure until you look at the code
Nov 28, 2018 23:31
No, it's an assumption that proper logic was used on the Join method.
Nov 28, 2018 23:30
void Join()
{
if (Username == null)
{
// workgroup join
}
else
{
// domain join
}
}
Nov 28, 2018 23:29
what if I wrote my join method as follows:
Nov 28, 2018 23:29
That's an assumption
Nov 28, 2018 23:28
when you deserialize it and call obj.Join() is that going to do a domain join or a workgroup join?
Nov 28, 2018 23:28
if I give you the following serialized object:
{
"JoinType" : "Workgroup",
"Name" : "MyDomain.Local",
"Username" : "administrator",
"Password" : "Password1"
}
Nov 28, 2018 23:25
Wouldn't that just be exactly option 1?
Nov 28, 2018 23:25
no need for a JoinType, no need for factory methods or VMToPoco methods ...
Nov 28, 2018 23:24
It's very similar to the solutions presented by Olivier Jacot-Descombes and Joe White - except that it is (in my opinion) a bit more robust
Nov 28, 2018 23:24
and on deserialization you have your INetworkJoin object well before you need to create the VM so you can pass it to the ctor of your VM.
Nov 28, 2018 23:23
What gets serialized is the ActiveJoin which is a concrete type
Nov 28, 2018 23:23
Yes. Although you can't argue that I move the problem around
Nov 28, 2018 23:21
But I agree with you that finding out the concrete type of my INetworkJoin property is not "pretty"
Nov 28, 2018 23:20
in that sense it's a much better solution than Option1
Nov 28, 2018 23:20
And you can no longer create a NetworkJoin with JoinType = Workgroup and Username set to something not null. Because you have concrete types now
Nov 28, 2018 23:19
There's no longer an assumption that the method Join() will use the JoinType to determine how to Join.
Nov 28, 2018 23:18
It's different from Option1 in the sense that what you serialize is a concrete type.
Nov 28, 2018 23:17
in order to do something with it
Nov 28, 2018 23:17
The problem is having to get the concrete type of the INetworkJoin object