C # decorator mode instance code,
Using System; using System. collections. generic; using System. linq; using System. text; namespace modifier {class Program {static void Main (string [] args) {ConcreteComponent con = new ConcreteComponent (); ConcreteDecoratorA a = new ConcreteDecoratorA ();. setComponent (con);. operation ();. addBehavior (); Console. writeLine ("=========================== "); concreteDecoratorB B = new ConcreteDecoratorB (); B .S EtComponent (a);. addBehavior (); B. operation (); B. addBehavior ();} public abstract class Component {public abstract void Operation ();} abstract class Decorator: Component {private Component component; public void SetComponent (Component component) {this. component = component;} public override void Operation () {if (component! = Null) {component. operation () ;}} class ConcreteDecoratorA: Decorator {public override void Operation () {base. operation ();} public void AddBehavior () {Console. writeLine ("Decorate Class A operations! ") ;}} Class ConcreteDecoratorB: Decorator {public override void Operation () {base. operation ();} public void AddBehavior () {Console. writeLine ("Decorate Class B operations! ") ;}} Public class ConcreteComponent: Component {public override void Operation () {Console. WriteLine (" operations on specific objects! ");}}}}
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.