In my course, I have been taught that, in general, In general, a class B should be responsible for creating instances of class A if one, or preferably more, of the following apply:Instances of B contain or compositely aggregate instances of AInstances of B record instances of AInstances of B closely use instances of AInstances of B have the initializing information for instances of A and pass it on creation.And in some more complex cases, the best place to create an object is within a factory class.My course has never taught me who should be responsible for deleting an instance. Say you want to delete an instance of A that has been created in an instance of B. Who deletes A? Is it A itself? Is it B? Is it some other class C that has a sole responsibility of deleting A?
Who is responsible for destroying an object?
design;design patterns;object oriented design;code quality