Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Objects Encapsulation and Arrays Null Reference

Shadab Khan
Shadab Khan
5,470 Points

Question regarding Path class encapsulation

Hi, I understand Jeremy's explanation on how encapsulation can foolproof the consumers of a class should the class creator decide to use another form of an array (List for e.g.) instead of simple arrays in the future. However, what happens to the existing consumers of the class in that case ? Won't their code break in case they're still passing an 'array' of path to perform path operations. How will a List cater for an array in that case then ?

2 Answers

Steven Parker
Steven Parker
231,275 Points

If backwards compatibility is an issue, the implementer should leave the original method and create the new one as an overload (same name, different argument(s)).

Optionally, the body of the original method can be modified to perform any necessary conversions and then call the new method.

Steven Parker
Steven Parker
231,275 Points

Aww, shucks. :blush: Glad I could help!