Aggregation in OOP

using System;

namespace Aggregation
{
    public class Address
    {
        public string addressLine, city, state;

        public Address(string addressLine, string city, string state)
        {
            this.addressLine = addressLine;
            this.city = city;
            this.state = state;
        }

    }

    public class Employee
    {
        public int id;
        public string name;
        public Address address; //employee Has-A address

        public Employee(int id,string name, Address address)
        {
            this.id = id;
            this.name = name;
            this.address = address;
        }

        public void Display()
        {
            Console.WriteLine(id+" "+name+" "+address.addressLine+" "+address.city+" "+address.state);
        }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Address a1=new Address("G-13","Sec-3","Noida");
            Employee e1=new Employee(1,"Sonoo",a1);
            e1.Display();
            Console.ReadKey();
        }
    }
}

I will discuss more later.

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.