Object oriented
- Process-oriented-analyze the steps required to solve the problem and then step through it
- Object-oriented-decomposing the things that make up a problem into objects
- An object is used to describe the behavior of something in a problem-solving process.
- Object-oriented three major features: encapsulation, inheritance, polymorphism
- Object-oriented program is more reusable, flexible and extensible
-
1 usingSystem;2 namespaceObjectdemo3 {4 //1. Create a refrigerator class by adding fields, properties, and methods to the class so that it has specific characteristics5 Public classRefrigerator6 {7 //Open the refrigerator door .8 Public voidOpen ()9 {TenConsole.WriteLine ("Open the refrigerator door ."); OneConsole.WriteLine ("turn on the light"); A } - - //close the refrigerator door the Public voidClose () - { -Console.WriteLine ("close the refrigerator door"); -Console.WriteLine ("Turn off the lights"); + } - + //Tuck sth into the refrigerator A Public voidPutIn (stringthing) at { -Console.WriteLine ("put"+ Thing +"Shove it in the freezer ."); - } - } - class Program - { in Static voidMain (string[] args) - { to //1. Open the refrigerator door + //2. Tuck the elephant into the refrigerator - //3. Close the refrigerator door the * //process-oriented thinking to achieve $Console.WriteLine ("Open the refrigerator door .");Panax NotoginsengConsole.WriteLine ("to shove an elephant into the freezer"); -Console.WriteLine ("close the refrigerator door ."); the + //realization of object-oriented thought A //2. Solve the problem by combining the behavior of the object therefrigerator RE =Newrefrigerator (); + Re. Open (); -Re. PutIn ("Elephant"); $ Re. Close (); $ - Re. Open (); -Re. PutIn (" Kitten"); the Re. Close (); - Wuyi } the } -}
"Learning Notes" C # Object oriented