0

XmlDictionaryWriter is an abstract class.
Why then does it have a constructor?

Why can its method "CreateBinaryWriter" return an instance of this abstract class?
I understand CreateBinaryWriter passes a stream to which the instance of this "abstract" class writes. It makes me wonder how abstract "abstract" really is...
By all that has been elaborated on the keyword abstract this does not fit the picture.
Code:

        MemoryStream WriteName(Name name)
        {
           var ms = new MemoryStream();
           var binary = XmlDictionaryWriter.CreateBinaryWriter(ms);
           var ser = new DataContractSerializer(typeof(FullName));
           ser.WriteObject(binary, name);
           return ms;
        }

Could s.o. explain?
thx

Andi Truman
  • 111
  • 1
  • 6

1 Answers1

0

I can't see full XmlDictionaryWriter hierarchy, but I think XmlDictionaryWriter.CreateBinary() is not a contructor but a static method; what can we see is an implementation of factory method pattern using static methods.
Is possible to call an abstract class' static method because a static method doesn't need an object instance (you can read more at Difference between Static methods and Instance methods)

Community
  • 1
  • 1
Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69