@
@
@atambalasi2016-12-08 12:19:51
OOP
@atambalasi, 2016-12-08 12:19:51

Do I understand encapsulation and object concepts correctly?

- encapsulation - when the internal state of objects can only be changed by the object itself (the ability of an object to maintain its internal state).
What an object is:
It is an entity that contains behaviors and data at the same time. This physical entity is located in the address space of the computer (also in the same place in memory).
An object has attributes such as attributes, states, behaviors.
An object can be considered a class, a group of classes, a subsystem.
What is the state of the object:
For example, if a person dyed his hair, then his state has changed. property hair color has changed values.
Example:
There is some abstract brain that can receive information in a linear fashion.
1) Data hiding stage

class Brain{

  String capsule;
}

We have already hidden the data, create the Brain class. Now he can only be contacted by creating an instance of this class. Other ways to get through to capsule no. Thus, only an object of this class can change the internal state of Brain.
We hide the data by creating the Brain class from the outside world. Race attributes are hidden from the outside world, only the object itself can change its internal state.
brain1 = new Brain();
brain2 = new Brain();

brain1.capsule = "Чайник";
brain2.capsule = "Магазин";

2) Stage hidden implementation details
class Brain{

  private String capsule;

  //Интерфейс методы для взаимодействия с объектом.(Слово интерфейс в широком понимании)
  public String getCapsule(){
    return capsule;
  }

  public void setCapsule(String data){

    if(!isBusy){
      //проверям является ли этот информация корректным
      //если да то проверям может ли мозг принят его
      if(isCorrect(data) && isAccept(data))
        capsule = data;
    }else{
      waitPleas();
    }
  }

  //Реализация
  private boolean isCorrect(String data){
    

  }

  //Реализация
  private boolean isAccept(String data){

  }

  private boolaen isBusy(){

  }
}

The Brain class has restricted data access and hidden implementation details. The client was given only interface methods.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question