Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Pro .NET 2.0 Code And Design Standards In CSharp (2006) [eng]

.pdf
Скачиваний:
34
Добавлен:
16.08.2013
Размер:
3.43 Mб
Скачать

266A P P E N D I X A E N V I R O N M E N T VA R I A B L E S A N D R E M OT E P R OX Y E X A M P L E

11.We now need to point the command box to UK_Client folder, so on the command line key in

cd ..\uk_client

and press Enter. For the client to have an association with the server functionality, it needs to know about the ProxyChiefDesignEngineer—open up Client.cs and note that an instance of ProxyChiefDesignEngineer needs to be created and two of its “knowledge methods” will be called. Presently, there is nothing in the UK_Client folder to help Client.cs access ProxyChiefDesignEngineer. Herein lies the trick: make a copy of ProxyRemoteServer DLL, which is located in the US_Server folder, and place it in the UK_Client folder. We now need to associate Client.cs with the DLL and also compile it into Client.exe. This will all be done at the same time when we enter the following command on the command line:

csc /r:proxyremoteserver.dll client.cs.

You should now have three files in the UK_Client folder: Client.cs,

ProxyRemoteServer.dll, and Client.exe, as shown in Figure A-9.

Figure A-9. UK_Client folder dialog

12.We have now set up both the server and client applications, so you can close the two instances of Windows Explorer that pointed to the respective folders. By the way, although this example is contrived, because we are working on a single PC, it need not be; we need only alter the TCP address in Client.cs from tcp://localhost:1234/ RemoteProxy to whatever address we choose, to allow remote client code to access the

ity permissions, etc.).

A P P E N D I X A E N V I R O N M E N T VA R I A B L E S A N D R E M OT E P R OX Y E X A M P L E

267

13.Now we are about to let the client call the service exposed by the server. Open up a second instance of the command box (see previous instructions). Align the two instances of the command boxes as shown in Figure A-10.

Figure A-10. US_Server and UK_Client dialog

14.We need to start up the service that will allow the UK technical guys to ask some questions. We do this by running server.exe from the command line. Key server.exe onto the command line that is pointed at US_Server. Calling server.exe will start the server application, as shown in Figure A-11.

Figure A-11. Server.exe dialog

268A P P E N D I X A E N V I R O N M E N T VA R I A B L E S A N D R E M OT E P R OX Y E X A M P L E

15.We now fire up the client application. Go to the command box that points to the UK_Client, and on the command line enter:

client.exe

which will start the client and immediately pose the questions to the US server. The answers will appear in the UK_client command box, as shown in Figure A-12.

Note If server.exe is not currently running, then a SocketException will be thrown.

Figure A-12. Server.exe and Client.exe dialog

16.In the UK_Client command box, notice that the first question has been answered by ProxyChiefDesignEngineer, because it was not an advanced question, whereas the second question was advanced and was answered by the ChiefDesignEngineer (refer to the code in ProxyChiefDesignEngineer to confirm this observation).

List of Standards

This is a list of the standards that are catalogued in the respective chapters of the book.

Code Policy Standards

The following standards are the code policy standards that appear in Chapter 1.

Code Policy

The standard acknowledges that a code policy is an effective and efficient way to successfully manage code development by coordinating development across the enterprise.

Code Management

The standard acknowledges that code is a valuable resource that benefits from management throughout its development and life cycle.

Code Vision

The standard acknowledges that a code vision creates a sense of direction that unites a development team to work toward a shared technical goal.

Code Objective(s)

The standard acknowledges that code objectives are an essential part of the development process because they identify what aspects of the enterprise need to change to realize a code vision.

Code Plan

The standard acknowledges the use of a code plan to identify tasks and allocate resources to progress code from its current state to its future state.

Code Strategy

The standard acknowledges that a code strategy can be used to determine the best way to implement a code plan and achieve a set of code objectives.

Code Development Methodology

The standard acknowledges the use of code development methodologies such as XP and RUP, which are used to maximize the likelihood of developing successful code.

269

270 L I S T O F S TA N D A R D S

Peer Review

The standard acknowledges the benefits of peer review: (1) improvement of the quality of code by improving the skills of the developer, (2) knowledge sharing, (3) compliance with code policies, and (4) building team cohesion.

Unit Testing

The standard acknowledges the importance of unit testing, which is used to examine the reliability of calling the methods of an object.

Refactoring

The standard acknowledges that refactoring is a useful tool to transform the internal workings of an application without affecting its external workings.

Enterprise Imperative

The standard acknowledges that developing code with an enterprise imperative improves efficiency by minimizing code duplication and maintenance.

Domain Imperative

The standard acknowledges that a domain imperative is used where a requirement is tightly coupled to a domain or there is insufficient opportunity or incentive to develop it otherwise.

Source Code Control

The standard acknowledges that a source code security control reduces the risks associated with team development.

Obsolescence

The standard acknowledges the benefits of early warning of obsolescence. Notice should be given in a timely manner: it is considered that a notice period of one major version is a minimum.

Code Style

The standard acknowledges the use of a code style to encourage uniformity or consistency in the way that code is written. It improves understandability of code and makes it relatively easy to rotate developers from project to project or from team to team.

Pascal Notation

The standard acknowledges the use of Pascal notation for class, constant, delegate, enum type, enum value, event, event handler, exception, static member variable, interface, method, namespace, and property.

Camel Notation

The standard acknowledges the use of Camel notation for instance member variables and parameters.

L I S T O F S TA N D A R D S

271

Hungarian Notation

The standard acknowledges the debate about the use of Hungarian notation with Web/Windows visual controls and notes it has steadfast and wide community support, thus making its use, for a variable assigned a visual control, optional.

Case Sensitivity

The standard acknowledges that where C# and Visual Basic are supported, for consistency in naming variables, a choice is made between (1) ruling against the use of case sensitivity in C# code; or (2) prefixing variables—in C# and VB code—with an underscore.

Code Structure Standards

The following standards are the code structure standards that appear in Chapter 2.

Assembly

The standard acknowledges that an assembly may be used to partition specialized functionality and to control distribution and accessibility to that functionality. The choices made to structure code impact not only accessibility to code but also the flexibility and maintainability of the code.

Namespace

The standard acknowledges the use of namespaces and embedded namespaces to strategically structure code and to avoid naming conflicts.

Interface Type

The standard acknowledges the use of namespaces and embedded namespaces to strategically structure code and to avoid naming conflicts.

struct Type

The standard acknowledges a struct type may be used as a lightweight alternative to a class to structure code and leverage interface inheritance in situations where memory allocation is scarce or class-inheritance and referencing are not required.

Class Type

The standard acknowledges the use of a class type where there is a requirement to support class-inheritance or reference semantics and the overhead of a reference type is not an issue.

Partial Type

The standard acknowledges the use of partial type where there is a requirement to split a type over multiple files but cautions that once the type is compiled, it cannot be extended.

Generic Type

The standard acknowledges the use of generics to reduce overhead and increase type flexibility while retaining the protection of type safety.

272 L I S T O F S TA N D A R D S

Code Development Standards

The following standards are the code development standards that appear in Chapter 3.

Top-Down Method

The standard acknowledges the use of the top-down development method to develop a solution by developing an application by decomposing a domain problem.

Bottom-Up Method

The standard acknowledges the use of the bottom-up development method to develop an application by composing a domain solution.

Application Architecture

The standard acknowledges the use of application architecture, observing that an application developed using architecture is more likely to be efficient and maintainable, as well as better equipped to accommodate volatility within the domain and the enterprise, than is an application that is not developed using architecture.

Class Development

The standard acknowledges that class development is complex and is an iterative process in which many elements have to be considered to build the most appropriate concrete classes, including interface, encapsulation accessibility, functionality, design patterns, inheritance, containment, and state.

Composition

The standard acknowledges the flexibility of composition in building a class interface and that it is favored over inheritance.

Class Inheritance

The standard acknowledges the use of class inheritance and notes that it is used to strategically and progressively extend and reuse design and functionality. It cautions that inappropriate base type selection is a common cause of reengineering.

Interface Inheritance

The standard acknowledges the use of interface inheritance as a versatile means to strategically implement an interface through using multiple interface inheritance, as required.

Overriding

The standard acknowledges the use of overriding to specialize generic functionality.

Overloading

The standard acknowledges the use of overloading as a low-risk way to vary or extend functionality, where the overloaded methods implement similar functionality using different types and numbers of parameters.

L I S T O F S TA N D A R D S

273

abstract Modifier

The standard acknowledges that the role of an abstract class is to contain generalized functionality or an interface and that the abstract method is used to defer implementation to a subclass.

sealed Modifier

The standard acknowledges the use of sealed to indicate that it is not logical or permissible to extend a class.

new Modifier

The standard acknowledges the use of new modifier to hide a derived method or delegate.

private Modifier

The standard acknowledges the use of the private modifier where there is a requirement to limit accessibility within a given class. Note that a class field should be modified private and its value accessed through a class property, to comply with encapsulation.

protected Modifier

The standard acknowledges the use of the protected modifier where there is a requirement to limit accessibility to a class hierarchy.

internal Modifier

The standard acknowledges the use of the internal modifier where there is a requirement to limit accessibility to other classes in the same program or assembly.

protected internal Modifier

The standard acknowledges the use of the protected internal modifier where there is a requirement to limit accessibility to a class, a class(es) derived from that class, or other classes in the same assembly.

public Modifier

The standard acknowledges the use of the public modifier where there is a requirement not to limit accessibility to functionality by defining and publishing an interface against which client code can collaborate.

static Modifier

The standard acknowledges the use of static to differentiate a class member from an object member and also to leverage the ability to access class functionality without the overhead of instantiation.

Attribute

The standard acknowledges the use of Attribute, which may be used to enrich an entity with metadata that may be accessed programmatically, at runtime.

274 L I S T O F S TA N D A R D S

Class Header

The standard acknowledges the use of class header, which comprises the keyword class, modifier, and class name. It is noted that consideration may be given to using a short and generic class name that is appropriate to the domain.

const

The standard acknowledges the use of const in simple situations or where the underlying value has to be a string type.

delegate

The standard acknowledges the use of delegate for programmatic efficiency and flexibility.

enum

The standard acknowledges the use of enum in situations that are complex or where a string type is not required as the underlying type of each constant value (otherwise, a const may be used).

event

The standard acknowledges the use of event as a way for objects to collaborate.

Field

The standard acknowledges that a field is associated with a class and is commonly used to store the underlying value of a property of an object, or if modified as static to store a value for the class.

Indexer

The standard acknowledges the use of indexer as a default property.

Method

The standard acknowledges the use of a method to support collaboration between objects and notes for efficiency, methods are functional-specific and developed to minimize the overhead of chatty communication between objects.

Property

The standard acknowledges the preferred use of property over the use of a public member field, in line with the object-oriented requirement to keep the internal workings of a class or object hidden from client code.

Variable

The standard acknowledges the definition of variable as a variable that has a procedurelevel association, as distinct from a member field, which is a variable that has a type-level association. A variable may be categorized as a local variable in a procedure (e.g., method); as an element of an array; or as an input or output parameter.

L I S T O F S TA N D A R D S

275

if

The standard acknowledges the use of if statement for simple branching.

if-else

The standard acknowledges the use of if-else statement where there is a requirement to have a single condition that explicitly identifies an alternative.

Nested if

The standard acknowledges the nested if statement. However, it is mindful of the adverse effect that deep nesting has on readability and productivity. Where a nesting exceeds two layers, consideration may be given to using a switch statement or encapsulating the logic in a method.

switch and case

The standard acknowledges the use of the switch and case statement as a conditional execution statement in any scenario where there are two or more options or conditions.

break

The standard acknowledges the use of a break statement in a switch block as an explicit way to alter the flow of execution.

default

The standard acknowledges the use of default label in a switch block to explicitly offer an option of last resort and as a way to prevent fall-through—which would result in a compile error.

continue

The standard acknowledges the use of continue statement to commence a new iteration at the closest iteration statement.

goto

The standard acknowledges the reluctance to use the goto statement and notes two accepted practices: using it within a switch statement to redirect the flow of control to a case statement or to a default label.

throw

The standard acknowledges the use of the throw statement to programmatically raise an exception to be handled.

try-catch

The standard acknowledges the use of the try-catch statement or block where there is not a requirement for the guarantee of a finally statement. It is mindful of the extra resources necessary to support the catch statement and the benefit of arranging them in descending likelihood of occurrence.

Соседние файлы в предмете Программирование на C++