Saturday

Factory's backdoor

class Factory { public class ProprietarySmartphone { protected string _osVersion; public string OsVersion { get { return _osVersion; } set { throw new Exception("Don't touch this!"); } } } private class DeveloperSmartphone : ProprietarySmartphone { public new string OsVersion { get { return _osVersion; } set { _osVersion = value; } } } public static ProprietarySmartphone BuyPhone() { var keepSecret = new DeveloperSmartphone(); Factory.OnSoftwareUpdate += delegete(int v) { keepSecret.OsVersion = v; }; var readyToSell = (ProprietarySmartphone)keepSecret; return readyToSell; } }

No comments:

Post a Comment