Go Lab [4] – struct, method, pointer receiver , receiver , interface, empty interface

  1. Struct Creation:
    • Define a struct Plane with fields: Manufacturer (string), Model (string), and Capacity (int).
    • Instantiate a Plane representing a specific model.
  2. Method with Receiver:
    • Add a method Details to the Plane struct that prints the plane’s manufacturer, model, and capacity.
  3. Pointer Receiver:
    • Add a method UpdateCapacity to the Plane struct that takes a new capacity as an argument and updates the Capacity field. Use a pointer receiver to make the changes persist.
  4. Interface:
    • Define an interface Aircraft with the method Details.
    • Ensure that the Plane struct implements this interface.
  5. Empty Interface:
    • Write a function DescribeAircraft that takes an argument of type interface{} and prints out the type and value of the argument.
    • Test this function by passing a Plane instance and other types.
  6. Putting it All Together:
    • Create a slice of Aircraft and add several different Plane instances to it.
    • Iterate over the slice, calling the Details method for each aircraft.
    • Use the DescribeAircraft function to print detailed information about each aircraft.

Leave a Reply

Your email address will not be published. Required fields are marked *