GNU Free Documentation License . .

()

: ,

  - (), .   , , , ,  - , . «» ( - , , JavaScript; ). , , , - . .

- , , . . - () .

, . , , , , , .   , ,   . - .

«», «», «» «» , .

[] , ,

- «» , . « » « » « », «, - ». - , ( , , , , , , , «», «» «», , ).

, « » ,   « ».

, , , , , ( ) . , () //. , .

,   , (), (). (, ,  /).   . , , , « ». « », «», « », «».

() «», «» «», , ( ) . , , « » //, , ,  . .

, //, , , . , ( ) . , ( ), , , ( ). , , , , .

, , , ,   , , , . , « », , .

[] ,

, , , , , . . , , , , .

, , , . , ( , ). , « » « », , , , « » « » , , « », .

, , . , , . , , . , , ( , - ). , - , .

[] , ,

, , . , , . «» « », , , , , . , «», « ».

  «» , . , , «».

- «» , . , - , . «» «» « ». , . , , , , () , , , ,  . . : . , , .

( ). - :

  • private (, )  , . . private , public- (++);
  • protected (, )  , , -. protected public- protected- - (++);
  • public ( )  . public (++);

. /, . ( ) , , . «», , , , , , ( , ).   .

[]

- ( php, Java, C++, Oberon, Python, Ruby, Smalltalk, Object Pascal) , ( , , ). ,   . , .

[]

  • ()  .
  •   .
  •   .
  •   .
  • -  , .

[]

[]

( ,   ) , .

- . ( Delphi) ( ), ( Java) ( Java  ), ( C++ C#) (namespaces), .

[] Object Pascal ( Delphi)

Delphi :

  TMyClass = class(TObject)
  private
    {        (  ,     ).}
    {    .}
  protected
    {           .}
  public
    {      .}
  published
    {          Object Inspector'e.}
  end;
  • TMyClass  ;
  • class  , ;
  • TObject  -, ;
  • private, protected, public, published  , .

() :

  MyClass := TMyClass.Create;

:

  FreeAndNil(MyClass);

[] C++

() C++ :

  class MyClass: public ParentClass // ParentClass  -,      
  {
      public:
         //         
         MyClass(); // 
         ~MyClass(); // 
         int classmember;
      protected:
         //          
      private:
         //        ;     
  };

.

(), .

  MyClass::MyClass()
  {
    //  
  }
  MyClass::~MyClass()
  {
    //  
  }

, :

  MyClass myinstance;

:

  myinstance.classmember

, , , , , , .

[] C#

C# :

public class MyClass
{
   //,    
   public int k;
   //,        
   internal int l;
   //,                   
   protected internal int m;
   //,        
   protected int n;
   //,      ( ).
   private int p;
}

C++ . , , :

public void DoSomething();
{
    var person = new
        {
         Name = "",
         Age = 15
        };
 
    var pet = new
        {
          Name = "",
          Type = "",
          Owner = person
        };
 
    Console.WriteLine("Age of pet owner: " + pet.Owner.Age);
}

[] Ruby

Ruby :

class MyClass
  def initialize
    #  ()
  end
 
  public #  public , ..   ,
         #   ,          
  def public_method
    #  
  end
 
  protected #  protected   ,     
            #        
  def protected_method
    #  
  end
 
  private #  private   ,     
          #      
  def private_method
    #  
  end
end

:

object = MyClass.new

: « », .

[] Python

Python class:

class MyClass:
      def __init__(self, arg):
          """"""
          self._arg = arg    #  
 
      def method1(self, x):
          """,    """ 
 
      def _method2(self, x):
          """,     """
 
      def __method2(self, x):
          """    """
 
      @staticmethod
      def method3(arg1, arg2, ...):
          """ ,       ,     """
 
      @classmethod
      def method4(cls, arg1, arg2, ...):
          """ ,       ,     ,       """

:

myinstance = MyClass(4)

, Python « ». ( ) :

del myinstance

[] Java

Java class:

  class MyClass {
      String name = "Example";
 
      // ""
      public MyClass(String name) {
          this.name = name;
      }
 
      // "" 
      public String getName() {
          return name;
      }
  }

:

  MyClass my = new MyClass("Example 2");

« » .

[] .

[]