Skip to content

Files

Latest commit

 

History

History
 
 

001_prereq

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

VARIABLE DECLARATION


DATA STRUCTURES

HANDS-ON

HANDS ON 1

- create a type square
- create a type circle
- attach a method to each that calculates area and returns it
- create a type shape which defines an interface as anything which has the area method
- create a func info which takes type shape and then prints the area
- create a value of type square
- create a value of type circle
- use func info to print the area of square
- use func info to print the area of circle

SOLUTION

HANDS ON 2

- create a struct that holds person fields
- create a struct that holds secret agent fields and embeds person type
- attach a method to person: pSpeak
- attach a method to secret agent: saSpeak
- create a variable of type person
- create a variable of type secret agent
- print a field from person
- run pSpeak attached to the variable of type person
- print a field from secret agent
- run saSpeak attached to the variable of type secret agent
- run pSpeak attached to the variable of type secret agent

SOLUTION

HANDS ON 3

- create an interface type that both person and secretAgent implement
- declare a func with a parameter of the interface’s type
- call that func in main and pass in a value of type person
- call that func in main and pass in a value of type secretAgent

SOLUTION

Thank you to @BenCarter78 for that cool solution.

ADDITIONAL INFO

- solution & optional additional info not necessary to know: assertions

SOLUTION

ADDITIONAL EXERCISES

Complete these exercises