Classes and Objects on the C# Programming Language

Classes and Objects on the C# Programming Language

Classes and Objects on the C# Programming Language

This time we will learn about classes and objects in one object-oriented programming language is C # programming language. OOP (Object Oriented Programming) is a method to the object-oriented programming. The purpose of OOP is created to facilitate the development of the program by following the existing model in everyday life.

In object-oriented programming there is some basic understanding that we need to know is:
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Class
5. Object

This time we will discuss about the Class and Object in OOP concepts and their application using the C# programming language

1. Class
Class is the extension of the concept of a data structure. Similar to the data structures, classes can contain data members (attributes), but the class also contains functions as part of its members.

2. Object
The object is an instance of the class. Under conditions of variables, a class would be the type, and the object will be variable.

Illustration of the manufacture of objects and classes in OOP (object oriented programming) 

Class: Radio
Object: my radio

Attribute:
Yellow
Kick Denim Brands
player Volume
The on / off

Method:
Increase the volume
Turning on the radio
Turn off the radio

From the example above, there is one object class with my radio Radio. Object in class Radio can be made more than one. We can create an object on my radio, your radio, radio was Edi, or radio does Sun. Many objects can be created from the same class as well as many radio stations that can be made of the same design image.

Access Specifier

Classes can have the same format as pure data structure, but the class is not only contains data. But also contains the functions that the functions contained renewal named access specifier.

    class Program {
          // Class Contains
    }

Access specifier consists of three basic key words are: private, public, and protected. The third modification of this specification will provide the right access to the members that follow.
  • Private, members who follow the private access only accessible to members from the same class.
  • Public, members who follow public access can be accessed from anywhere by anyone during the class object visible (recognizable).
  • Protected, member who follows the protected access only accessible to members from the same class. But it can also be accessed by members of the derived class (derived class).

How to define a class

When will define a class, then the class must also define a series of data types. This does not mean class defines the actual data, just declare the class definition of the name and type of data that the object of the class will be consistent with the operations that will be presented later.

Here's an example of defining a class.

namespace Modul_Csharp {
    class Foods {
        // Class Attribut
        private string code;
        private sting brand;
        private int stock;

        //class method
        public bool StockValidation() {
           If (Stack <= 0) {
               Console.Writeline("Stock is Empty!!!");
               Stock = 0;
               return false;
           } else {
               return true;
           }
        }
     }
}

Of pieces of script above can be seen how a class named Student declared. In the classroom, it is known to have members in the form of data and functions with a description of, among others, there are three pieces of data with a string type that code, brand, and integerstock, where the data have private access to the specification. and grade fruit Foods also has a function that is StockValidation (), in which the function has access to public specifications.

It can be concluded pendefinian real class discount some important rules. in the form of complete classes have data (commonly known by the name attribute), functions (commonly known by the name of the method). Where the later function / method can be divided into several sections, among others: Constructor, Properties and Method.
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment