As Robert C. Martin Explains it:
Association represents the ability of one instance to send a message to another instance. This is typically implemented with a pointer or reference instance variable, although it might also be implemented as a method argument, or the creation of a local variable.
[Example:]
|A|----------->|B|
class A
{
private:
B* itsB;
};
Aggregation [...] is the typical whole/part relationship. This is exactly the same as an association with the exception that instances cannot have cyclic aggregation relationships (i.e. a part cannot contain its whole).
[Example:]
|Node|<>-------->|Node|
class Node
{
private:
vector
};
The fact that this is aggregation means that the instances of Node cannot form a cycle. Thus, this is a Tree of Nodes not a graph of Nodes.
Composition [...] is exactly like Aggregation except that the lifetime of the 'part' is controlled by the 'whole'. This control may be direct or transitive. That is, the 'whole' may take direct responsibility for creating or destroying the 'part', or it may accept an already created part, and later pass it on to some other whole that assumes responsibility for it.
[Example:]
|Car|<#>-------->|Carburetor|
class Car
{
public:
virtual ~Car() {delete itsCarb;}
private:
Carburetor* itsCarb
};
Thursday, April 19, 2007
What is the difference between Aggregation and Composition
Posted by
Don
at
3:06 AM
0
comments
How do you modify Code Access Security Policy?
The Code Access Security Policy tool enables users and administrators to modify security policy for the machine policy level, the user policy level, and the enterprise policy level.
http://msdn2.microsoft.com/en-us/library/cb6t8dtz(VS.80).aspx
Posted by
Don
at
2:39 AM
0
comments
What would you have to do to implement an asynchronous Web service method
-
Split a synchronous Web service method into two methods, each with the same base name, one with that name starting with Begin and the other End.
-
The parameter list for the Begin method contains all the in and by reference parameters for the method's functionality plus two additional parameters.
-
By reference parameters are listed as in parameters.
-
The second from the last parameter must be an AsyncCallback. The AsyncCallback parameter allows a client to supply a delegate, which is invoked when the method completes. When an asynchronous Web service method calls another asynchronous method, this parameter can be passed into the second from last parameter for that method.
-
The last parameter is an Object. The Object parameter allows a caller to supply state information to the method. When an asynchronous Web service method calls another asynchronous method, this parameter can be passed into the last parameter for that method.
-
The return value must be of type IAsyncResult.
-
-
The parameter list for the End method consists of an IAsyncResult followed by any out and by reference parameters specific to the method's functionality.
-
The return value is the same type as the return value of a synchronous Web service method.
-
By reference parameters are listed as out parameters.
-
Example
using System;
using System.Web.Services;
[WebService(Namespace="http://www.contoso.com/")]
public class MyService : WebService
{
public RemoteService remoteService;
public MyService()
{
// Create a new instance of proxy class for
// the Web service to be called.
remoteService = new RemoteService();
}
// Define the Begin method.
[WebMethod]
public IAsyncResult BeginGetAuthorRoyalties(String Author,
AsyncCallback callback, object asyncState)
{
// Begin asynchronous communictation with a different XML Web
// service.
return remoteService.BeginReturnedStronglyTypedDS(Author,
callback,asyncState);
}
// Define the End method.
[WebMethod]
public AuthorRoyalties EndGetAuthorRoyalties(IAsyncResult
asyncResult)
{
// Return the asynchronous result from the other Web service.
return remoteService.EndReturnedStronglyTypedDS(asyncResult);
}
}
Posted by
Don
at
12:12 AM
0
comments
Wednesday, April 18, 2007
Interface Inheritance
Is interface inheritance possible? Why is it required? why wouldn't I implement 2 interfaces instead of doing an interface inheritance?
Ans: Suppose there is a class that I want to function as a Bank Account. Now there are 5 classes that are 5 different types of Bank Accounts which have a function CalculateInterest(). I would define an interface called IBankAccount Interface and implement this interface in my 5 classes to make them BankAccounts. Now I want one bank account to do something special. It should contain all the existing functions of a normal bank account and should specialize in something.
So I would create a new Interface say, ISpecialBankAccount and inherit it from IBankAccount. Now in my special class I would implement ISpecialBankAccount.
Now I can omit the inheritance of interfaces and implement both these interfaces. And from the code perspective it would be the same thing. But when I am breaking the rules of OO. From a design perspective it would make more logical sense. because ISpecialBankAccount would contain all the functions of the IBankAccount interface and it would add special functionality to it.
So Implementing ISpecialBankAccount in our special class would keep the existing bank account as they are and would also have special features of the ISpecialBankAccount.
Posted by
Don
at
10:57 PM
0
comments