exporting/

directory
v0.0.0-...-20bc30d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2016 License: Apache-2.0

README

Packaging / Exporting

Packages contain the basic unit of compiled code. They define a scope for the indentifiers that are declared within them. Learning how to package our code is vital because exported identifiers become part of the packages API. Stable and useable API's are incredibily important.

Notes

  • Code in go is complied into packages and then linked together.
  • Identifiers are exported (or remain unexported) based on letter-case.
  • We import packages to access exported identifiers.
  • Any package can use a value of an unexported type.
  • Package design and understanding the components you need is critical.

http://blog.golang.org/organizing-go-code
http://blog.golang.org/package-names
http://www.goinggo.net/2014/03/exportedunexported-identifiers-in-go.html
http://www.goinggo.net/2013/08/organizing-code-to-support-go-get.html
Structuring Applications in Go - Ben Johnson

An Interview with Brian Kernighan

http://www.cs.cmu.edu/~mihaib/kernighan-interview/index.html

I think that the real problem with C is that it doesn't give you enough mechanisms for structuring really big programs, for creating ``firewalls'' within programs so you can keep the various pieces apart. It's not that you can't do all of these things, that you can't simulate object-oriented programming or other methodology you want in C. You can simulate it, but the compiler, the language itself isn't giving you any help. - July 2000

Design Guidelines

Code Review

Declare and access exported identifiers - Pkg (Go Playground)
Declare and access exported identifiers - Main (Go Playground)

Declare unexported identifiers and restrictions - Pkg (Go Playground)
Declare unexported identifiers and restrictions - Main (Go Playground)

Access values of unexported identifiers - Pkg (Go Playground)
Access values of unexported identifiers - Main (Go Playground)

Unexported struct type fields - Pkg (Go Playground)
Unexported struct type fields - Main (Go Playground)

Unexported embedded types - Pkg (Go Playground)
Unexported embedded types - Main (Go Playground)

Exercises

Exercise 1

Part A Create a package named toy with a single exported struct type named Toy. Add the exported fields Name and Weight. Then add two unexported fields named onHand and sold. Declare a factory function called New to create values of type toy and accept parameters for the exported fields. Then declare methods that return and update values for the unexported fields.

Part B Create a program that imports the toy package. Use the New function to create a value of type toy. Then use the methods to set the counts and display the field values of that toy value.

Template | Answer


All material is licensed under the Apache License Version 2.0, January 2004.

Directories

Path Synopsis
Sample program to show how to access an exported identifier.
Sample program to show how to access an exported identifier.
counters
Package counters provides alert counter support.
Package counters provides alert counter support.
Sample program to show how the program can't access an unexported identifier from another package.
Sample program to show how the program can't access an unexported identifier from another package.
counters
Package counters provides alert counter support.
Package counters provides alert counter support.
Sample program to show how the program can access a value of an unexported identifier from another package.
Sample program to show how the program can access a value of an unexported identifier from another package.
counters
Package counters provides alert counter support.
Package counters provides alert counter support.
Sample program to show how unexported fields from an exported struct type can't be accessed directly.
Sample program to show how unexported fields from an exported struct type can't be accessed directly.
users
Package users provides support for user management.
Package users provides support for user management.
Sample program to show how to create values from exported types with embedded unexported types.
Sample program to show how to create values from exported types with embedded unexported types.
users
Package users provides support for user management.
Package users provides support for user management.
exercises
exercise1
Create a package named toy with a single exported struct type named Toy.
Create a package named toy with a single exported struct type named Toy.
exercise1/toy
Package toy contains support for managing toy inventory.
Package toy contains support for managing toy inventory.
template1
Create a package named toy with a single exported struct type named Toy.
Create a package named toy with a single exported struct type named Toy.
template1/toy
Package toy contains support for managing toy inventory.
Package toy contains support for managing toy inventory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL