Class composition : Composition : Class Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Class » Composition »

 

Class composition


 

package
{
    public class Employee
    {
        public function doWork():int
        {
            return 1;
        }
    }
}
    class Manager
    {
        protected var employees:Array;

        public function Manager(numberOfEmployees:int)
        {
            employees = new Array();
            for (var i:int 0; i < numberOfEmployees; i++)
            {
                employees[inew Employee();
            }
        }

        public function delegateWork():int
        {
            var totalWork:int 0;
            for each (var employee:Employee in employees)
            {

                totalWork += employee.doWork();
            }
            return totalWork;
        }
    }

    class Company
    {
        public function Company()
        {
            var manager:Manager = new Manager(10);
            var completedWork:int = manager.delegateWork();
            trace(completedWork)//10
        }
    }

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Class
» Composition