about serializable

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

Below you can see two different ways to create a BinaryFormatter to use when
serialize object and collections.

I know that BinaryFormatter implement IFormatter that's why you can use
IFormatter in the way that is done here.

IFormatter serializer = new BinaryFormatter();
BinaryFormatter serializer = new BinaryFormatter();

Now to my question assume I'm only interested in method Serialize and
Deserialize which exist in IFormatter is it then
better to use IFormatter as compile type instead of BinaryFormatter.

So can I then say as a rule use the compile type that is most general and
can access the methods.

//Tony
 
In reality, you aren't likely to want to change the formatter and it
isn't something you often need to be strategy-specific / factory
based.

I can't think of much benefit here - I'd just code against
BinaryFormatter; it is then clear what you are using... of course, if
you genuinely have a need to use multiple binary formatters (perhaps
you want to use "protocol buffers" ;-p) then code against IFormatter.

(note to self: implement IFormatter on protobuf-net...?)

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top