Very Impressive Azure tutorial. The content seems to be pretty exhaustive and excellent and will definitely help in learning Azure course. I'm also a learner taken up Azure training and I think your content has cleared some concepts of mine. While browsing for Azure tutorials on YouTube i found this fantastic video on Azure. Do check it out if you are interested to know more.https://www.youtube.com/watch?v=F2mZxlaEOtI
The confusion is that in the article it says that the dependency relationship is when:
Quote:
class A receives an instance of class B as a parameter to at least one of its methods. You would also use dependency to indicate that class A creates an instance of class B local to one of its methods (on the stack).
And what I'm looking here in the example of association seems to be that same description, The "SwipeCard"class is receiving an instance of the "Manager"class as parameter of the "Swipe" method and vice-versa.
The Difference between Association and Dependency is soo thin.
Association:
When you are holding the state of the source object in your dependent object and you pass the state of the source object through constructor or any getter/setter it is called as association.
Dependency:
When you invoke any of the method aka API of the source object where the source object is passed through to your dependent object as a method argument if there is any changes in the source object definition you need to change the dependent objects code too.
Also, whenever you are using Association you will mostly use Dependency too.
Example.
//Association
==============
Class ImageDownloader{
Image image;//using an image field.
// use either a constructor or setter getter to set value for the field image.
public ImageDownloader(Image image){
this.image=image;
}
public void setImage(Image image){
this.image=image;
}
public Image getImage(){
return image;
}
}
//Dependency
==============
Class ImageDownloader{
// no field holding the state of image.
public void download(Image image){
// some code to download
File.copy(image.url(), //localdest); // if we are calling url() method of Image class image.url() a dependency exist here.
//We are dependent(need to change our code) on the changes to be done in the method definition in Image class. example Image.url() myt be returning Path object before but now if they modified it to return String/URL object we need to modify our code in download() method to create a Path object of the String/URL and then pass it to the argument of copy.
}
}
//Association relation which inturn uses Dependency (Most predominantly association is used this way only)
Class ImageDownloader{
Image image;//using an image field.
// use either a constructor or setter getter to set value for the field image.
public ImageDownloader(Image image){
this.image=image;
}
public void setImage(Image image){
this.image=image;
}
public Image getImage(){
return image;
}
//here we are using the dependency relation too
public void download(Image image){
// some code to download
File.copy(image.url(), //localdest); // if we are calling url() method of Image class image.url() a dependency exist here.
//We are dependent(need to change our code) on the changes to be done in the method definition in Image class. example Image.url() myt be returning Path object before but now if they modified it to return String/URL object we need to modify our code in download() method to create a Path object of the String/URL and then pass it to the argument of copy.
}
For aggregation its mentioned that Child objects belong to a single parent (in summary table).
As per my understanding in aggregation the child object can be aggregated by other objects also and hence can have more than one parent. Is my understanding correct?
Wanted to thanks for providing good explanation and difference between Association, Aggregation and Composition.
It was good and helpful that you explained clearly with code constructs.
You are a .NET guru. I read your .NET interview books completely and it helped me a lot. This article is also very useful. Thank you. Keep up the good work.
hey in case of aggregation, how you initialize worker object in class scope. you have to initialize in somewhere method. because as by u did, this behavior matches to composition. if manager obj destroy so worker will also destroy bcoz worker behaves like manager data item. please if i am wrong. correct me through khayamabdulnasir@gmail.com
thank you.
best regards
nasir
Last Visit: 31-Dec-99 18:00 Last Update: 23-Apr-24 14:41