Answer the question
In order to leave comments, you need to log in
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;
}
brain1 = new Brain();
brain2 = new Brain();
brain1.capsule = "Чайник";
brain2.capsule = "Магазин";
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(){
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question