5.5.3 accesses got-up accord with
Accessed got-up accord with to define certain code to be opposite kind of member (like method and attribute) access grade.The access that you must give every member to add a hope decorates accord with,Otherwise,Acquiescent access the type is implicit.
You can apply 4 to access one of got-up accord with:Public — can visit this member anyplace,This is to have the access of least limitation to decorate accord with.Protected — in kind reach all derive kind in can visit this member,Do not allow exterior visit.Private — be in merely same kind internal ability visits this member.Even derive kind cannot visit it.Internal — allow same package (applied process or library) all code are visited.In.NET component level,You can regard it as Public,And outer ministry is Private.
To demonstrate to access the usage of got-up accord with,I altered Triangle case a little,Make it included the region member that adds newly and a new derive kind (see detailed list 5.13) .
Detailed list 5.13 is in kind in use access got-up accord with
1: Using System;2:
3: Internal Class Triangle
4: {
5: Protected Int M_a, m_b, m_c;
6: Public Triangle(int A, int B, int C)
7: {
8: M_a = A;
9: M_b = B;
10: M_c = C;
11: }
12:
13: Public Virtual Double Area()
14: {
15: / / Heronian Formula
16: Double S = (m_a + M_b + M_c) / 2nj
17: Double DArea = Math.Sqrt(s*(s-m_a)*(s-m_b)*(s-m_c));
18: Return DArea;
19: }
20: }
21:
22: Internal Class Prism:TRiangle
23: {
24: Private Int M_h;
25: Public Prism(int A, int B, int C, int H):bAse(a, b, c)
26: {
27: M_h = H;
28: }
29:
30: Public Override Double Area()
31: {
32: Double DArea = Base.Area() * 2.0;
33: DArea += M_a*m_h + M_b*m_h + M_c*m_h;
34: Return DArea;
35: }
36: }
37:
38: Class PrismApp
39: {
40: Public Static Void Main()
41: {
42: Prism Prism = New Prism(2, 5, 6, 1);
43: Console.WriteLine(prism.Area());
44: }
45: }
Triangle kind with Prism kind be by mark now Internal.This means them to be able to be visited in current package only.
Remember please ” .NET component ” what this term points to is to pack (Packaging, ) ,is not you the component that the likelihood uses in COM+ .
Triangle kind have three Protected member,They are in tectonic function by initialization,In be being used at area calculative method.Because these members are Protected member,So I can be in derive kind they are visited in Prism,Different area is carried out to calculate over.
Him Prism added M_h of a member newly,It is illicit some — even derive kind also cannot visit it.
Spend some of time to be every kind of member even every kind the plan protects administrative levels one kind,It is a good idea normally.Introduce when need when revising,Comprehensive plan can help you finally,Because do not have programmer to be able to be willing to use ” without documentation ” kind of function.
5.6 brief summary
This chapter showed kind all sorts of element,It is moving example (object) pattern plate.In the lifetime of an object,The code that is implemented above all is a tectonic function.Tectonic function uses initialization variable,These variable are used at computational result in the method later.
The method allows you to pass a cost, cite to variable,Only deferent perhaps an output is worth.The method can be adapted with realizing new function,Or you are OK screen radical kind member,If it came true,one is had and derive kind the member is identical the method of the name.
Name attribute to be able to be regarded as region member (the member is variable) or attribute accesses a mark to come true.Latter is Get and Set access a mark,Oversight or another,You can be founded be written only or read attribute only.Access a mark special agree with the value that affirms the ode gives property.
C# kind another function is index,Kind of median is visited to become a possibility like grammar of its liken array.Still have,If become kind of medium certain thing when happening,You think the client gets an announcement,Should let they and incident correlation.
Collect when rubbish implement when transferring analyse form function,The life of the object ended.When can because you cannot forecast this kind of condition well and truly,happen,Should establish a method so with releasing these valuable resource,When your disuse when them.