Examples of object collaboration

Object collaboration is one of the most important topics in OOP. If the objects don't collaborate with each other in a program, nothing can be achieved. For example, if we think about a simple web application, we can see how the relationship between different objects plays an important role in constructing the application. Twitter, for example, has many objects that are related to each other in order to make the application work. The User object consists of the username, password, first name, last name, picture, and other user-related information belonging to Twitter users. There could be another object called Tweet that consists of a message, date and time, the username of the user who posted the tweet, and some other properties. There may also be another object called Message that holds the content of the message, who it was from, who it was sent to, and the date and time. This is the simplest breakdown possible for a big application like Twitter, it almost certainly contains many other objects. But for now, let's just think about these three objects and try to find a relationship between them.

First, we will look at the User object. This is one of the most important objects in Twitter as it holds the user information. Everything in Twitter is either made or performed by a user or for a user, so we can assume that there should be some other objects that will need to have a relationship with this User object. Now let's try to see whether the Tweet object has any relationship with the User object or not. A tweet is a message that should be available for all users to see if the Tweet object is public. If it is private, only that user's followers will see it. As we can see, a Tweet object has a very strong relationship with a User object. So, with the OOP approach, we can say that the User object has a collaboration with the Tweet object in the Twitter application.

If we also try to analyze the relationship between User and Message objects, we will see that the Message object also has a very strong relationship with the User object. A message is sent by a user to another user, therefore, without a user, the Message object has no proper implementation.

But is there any relationship between the Tweet and Message objects? From what has been said, we can say that there is no relationship between these two objects. It's not necessary for every object to be related to all other objects, but an object usually has a relationship with at least one other object. Now let's see what different types of object collaborations are available in C#.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.154.121