vb.net - Nested class & readonly properties -
outside class i'd able access cctv.camera.brightness property readonly, methods within cctv class should able modify brightness property. please can advise on how achieve this?
i think need add interface exposes properties , hides others, i'm not sure of implementation. [note constructor , main sub contrived example , testing].
public class cctv public class camera public property name string public property brightness integer end class dim cameras new dictionary(of string, camera) public sub new() dim cam new camera cam.name = "driveway" cam.brightness = 5 cameras.add(cam.name, cam) end sub public sub changebrightness(value integer) cameras("driveway").brightness = value end sub end class sub main() dim mycctv = new cctv mycctv.changebrightness(10) if mycctv("driveway").brightness = 10 console.write("brightness 10") end sub
get getter , setter of property can have different accessibility modifiers. in case want brightness readable code trust should able write it. this:
public class camera private _brightness integer public property brightness integer return _brightness end friend set(value integer) _brightness = value end set end property '' etc... end class
note added friend
keyword, limits access code in same project camera class part of. can private
or protected
if want limit access code inside camera class or derived classes.
Comments
Post a Comment