The first step to perform is creating an interface. To accomplish this, follow these steps:
1. Right-click the designer surface (see Figure 17.1) and select the Add, Interface command.
2. When the New Interface dialog appears, specify the IPerson
name and leave all other options unchanged, which are self-explanatory. Figure 17.2 shows the dialog. This adds a new item on the designer, representing an interface.
3. Right-click the new interface and select the Add, |Property command. For each object type the context menu provides specific commands related to members that the particular object can contain. Figure 17.3 shows how you can accomplish this. When the new property is added to the interface, it is focused and highlighted for renaming, so rename it to FirstName
. Notice that the default type for members is Integer
; therefore, you need to open the Properties window (by pressing F4) and write the appropriate type in the Type field.
4. Repeat the previous step to add a new LastName
property and a FullName
method, both of type String
. About methods, the Class Designer implements Sub
methods by default that are switched to Function
when you specify a return type via the Properties window. This step is shown in Figure 17.4.
If you now double-click the new interface, Visual Studio 2010 shows the code that it generated behind the scenes, as shown in Listing 17.1.
The next step is to add an abstract class named Person
, which serves as the base class for subsequent classes. To accomplish this, right-click the designer and select the Add, Abstract Class command. Name the new class Person
and, when ready, you notice within the designer that is marked as MustInherit
. Next, double-click the new class and add an Implements IPerson
statement below the class declaration. This ensures that the new class is going to implement the IPerson
interface. This is reflected in the class diagram and confirmed by the appearance of properties and methods defined within the interface inside the new class and by a rounded symbol that identifies an interface relationship. Figure 17.5 shows the result of the preceding operations.
Listing 17.2 shows the full code for the Person
class.
Notice how the FullName
method is declared as MustOverride
. The Properties window offers deep control to classes. Table 17.2 summarizes the most important properties except those related to filenames and locations.
The Properties window also offers the Remarks and Summary fields that allow specifying descriptions under the form of XML comments, and this feature is available for all members, not just classes. Also, the Properties window shows the Generic, Implements, and Inherits fields which are disabled by design.
18.219.209.80