Walmart Labs Interview Question
Applications DevelopersCountry: India
Interview Type: In-Person
If this were C++, the issue would be which of the changes affect the layout of the object. Code which uses the affected class will likely make inappropriate accesses when they access fields as they assume the old layout. Bugs from this will likely be very hard to diagnose.
Adding a data member typically changes the object layout though in some app compat cases people add a field and shrink another. This is not 100% safe, it depends on how the fields are accessed, so best to avoid.
If the class had no other virtual methods before adding a virtual destructor, then the addition a virtual method will change object layout to include a vtable pointer. It's an implementation detail, but this is typically at the start of the object so all fields shift by the vtable pointer size.
Adding new methods does not and the existing libraries can't call them.
Probably worth pontificating that you absolutely never want to ship out of date libraries, better to build everything against a known point.
This is obviously a C++ question (mentions virtual destructor).
C++ ABI isn't standardized and answers depend on bunch of implementation details, but for most of the compilers all the changes a,b,c,d are generally unsafe.
For each case (a,b,c,d) there are numerous "safe" special cases.
For instance changing a signature of non-virtual method which was never called is safe, or introducing a data-field to a class whose layout is never observed by the client code (directly or indirectly via inlined functions), so on.
incorrect. This is generally unsafe.
It could be safe only in some edge cases.. E.g. on most compilers it will be safe IF: class already had a virtual method AND the destructor is never called on a base class pointer from the client code (directly or indirectly via all forms of inlining).
Couple of things, from .Net perspective
- Jai December 04, 20141. if you make any changes to the above new assemblies version is created and we can have multiple version assemblies.
2. When you have new version of and what to reference it you will have to recompile the code.