0

you might know that we have 2 kinds of classes based on activities , passive class and active class. I just know that active class is a class which needs to use from all of the CPU like web services or windows while loading.

can u help me about passive class with some examples about it.

Neda
  • 77
  • 9
  • possible duplicate of [Active class versus passive class](http://stackoverflow.com/questions/14565544/active-class-versus-passive-class) – bdulac Jan 23 '15 at 18:18

2 Answers2

4

An active class is one where an instance of the class starts its behaviour as soon as it is created. This behaviour is typically specified using activities or state machine. The behaviour terminates when the instance is destroyed.

A passive class has behaviour that is defined by its operations. This behaviour only starts when one of the operation is called on an instance of that class. The behaviour terminates once the operation returns.

CharlesRivet
  • 542
  • 2
  • 7
  • thank u very much but if it is possible please use an example to describe it because I don't understand what you mean by behaviour ?? you mean that we have some functions in this class that when an object of the class calls one function it executes , so when do we use passive classes just in programs that we write , I need a clear example !! for example is word program a passive class and when we use bold we r calling a function?? please explain more asap. thanx – Neda Jan 23 '15 at 17:25
  • An active class is one where the behaviour starts when it is instantiated, without any further external stimuli. For example, a polling class checking for some situation to happen (e.g., a file being created or changing) and reacting to that situation. Active class behaviour can easily be expressed, for example, as a state machine or an activity with an initial node. – CharlesRivet Jan 28 '15 at 13:27
  • Active classes: Web servers, polling mechanisms, continuous process monitors, "M" and "V" in the MVC UI pattern. Passive classes: data stores and manipulation, "C" in the MVC UI pattern. – CharlesRivet Jan 28 '15 at 13:40
3

The great majority of classes that you will design are passive. This means that they get instantiated, their methods get called, and they perform the operations defined in their methods. In effect, they do what they do when they are asked to, by another object calling one of their methods.

Active objects, on the other hand, do what they do as a consequence of being created. Implementation typically has a private method that gets called in the object's constructor in some way.

A simple and visual example of an active object is this (borrowed from here). Suppose you want to simulate rain falling down a screen. Each raindrop is simply a ball falling from the top of the screen to the bottom. So you have an active class called Drop, which draws a filled circle at a random x coordinate at the top of the screen, and moves it in increments to the bottom. (Again, this behavior occurs by calling a private method in the constructor.) A RainMaker class simply instantiates Drop classes, perhaps at random intervals of time.

The Drop class is active because it doesn't need to be told to fall from the top of the screen to the bottom. It does that by the fact of having been instantiated.

Most examples are more complex, because most active objects need to interact with other objects during their lifetime to do anything useful (and these Drop objects don't). An indicator of an active object is that it controls when it executes operations it's asked to execute. So, asynchronous messaging queues and that sort of thing are indicators.

This gives some more advanced information.

BobRodes
  • 5,990
  • 2
  • 24
  • 26