Low cost ecommerce web development India flash website design

Spotting the Difference

The general “thought test” to spot whether object A aggregates or composes object

B is to ask, “What happens if object A dies? Will object B still be alive?” If object

B outlives the death of object A, object A is said to aggregate object B. But if

object B dies when object A dies, then object A is said to compose object B.

In terms of practical development, knowing when to apply aggregation or composition

is important.

Aggregation has the advantage of lower overhead, because a single object will be

shared by many other objects. Certainly, aggregating your database connection

class is a good idea; composing it with every object that wants to make a query

may require you to have multiple connections to your database, which will quickly

halt your application when your site attracts high levels of traffic.

Composition has the advantage of making classes easier to work with from the

outside. The code that uses the class doesn't have to worry about passing it the

other objects it needs, which, in a complex application, can often become tricky

and result in a design “work around.” Composition also has the advantage that

you know exactly which class has access to the composed object. With aggregation,

another object sharing the aggregated object may do something to its state that

“breaks” the object as far as the other classes that use it are concerned.

website designer freelance ASP PHP ecommerce web developer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110