Hello! At the moment I am studying OOP and I am confronted with a misunderstanding of the phrase “sending a message”.
Here is a very simplified presentation: Suppose we have two classes X and Y. In class X, there is a getData method that returns some data. In class Y, there is a handleData method that processes data and returns new ones. Here is the code:
class X { getData() { return 'some data'; } } class Y { handleData(data) { return data + 'some operation on data'; } } // создаём объекты const x = new X(); const y = new Y(); // вызываем методы let data = x.getData(); let handledData = y.handleData(data); And here's the actual question: Can we say from the code above that object y sends a message to object x ? does it use data from object x ?
Or I’m mistaken and the term “send a message” to OOP is if the object x were used inside the object y the implementation would be:
class X { getData() { return 'some data'; } } class Y { constructor() { this._x = new X(); } handleData() { let data = this._x.getData(); return data + 'some operation on data'; } } // создаём объект const y = new Y(); // вызываем метод let handledData = y.handleData();