ProgramGuru

Contact Management System

Start with Contact Management System

Learn contact management system through an executable example, then connect the small demonstration to production code.

What you’ll learn

  • Explain the main purpose of contact management system.
  • Read and run the complete Go example in this lesson.
  • Apply the concept and recognize common mistakes.

Understand the idea

A contact manager stores people by a stable identifier and supports create, read, update and delete operations. Use a map for the in-memory index and sort keys to produce deterministic output.

This learning version updates one contact and prints all remaining contacts in alphabetical key order.

Visualize how it works

Follow this diagram before executing the example. Check where a value or decision changes what runs next.

Visual explanation for contactsStable identifiers make updates and deletions predictable.Receive commandStep 1Validate contactStep 2Update keyed storeStep 3Show resultsStep 4Stable identifiers make updates and deletions predictable.
Stable identifiers make updates and deletions predictable.

Tools, syntax and practical notes

Expansion: implement a CLI menu or REST endpoints, JSON persistence, unique identifiers, search and field validation. Test updates and deletions of nonexistent IDs.

Run a complete Go example

This example is a complete program. Save it as main.go or paste it into the Go Playground.

Go code

package main

import (
	"fmt"
	"sort"
)

type Contact struct{ Name, Email string }

func main() {
	contacts := map[string]Contact{"a1": {"Asha", "asha@example.test"}, "b2": {"Bala", "bala@example.test"}}
	contacts["b2"] = Contact{"Bala", "bala.new@example.test"}
	keys := make([]string, 0, len(contacts))
	for key := range contacts {
		keys = append(keys, key)
	}
	sort.Strings(keys)
	for _, key := range keys {
		fmt.Println(key, contacts[key].Name, contacts[key].Email)
	}
}

Output

a1 Asha asha@example.test
b2 Bala bala.new@example.test

Trace what the program does

The map starts with two contacts. Reassigning b2 changes its email, and sorting the keys ensures that a1 prints before b2.

Avoid common mistakes

  • A person’s display name should not automatically be treated as a unique ID.
  • Validate contact fields and consider privacy, backups and delete behavior before deployment.

Try it yourself

Implement Add, Find, Update and Delete methods and verify missing-ID responses.

Tip: Edit the example above, predict the output, and run the modified code to test your reasoning.

Check your understanding

Which structure gives efficient key-to-contact lookup in memory?
Choose one answer. You can try again.

Answer and explanation

map[string]Contact

Correct. The map starts with two contacts.

What you should remember

You have practiced Contact Management System in a small, self-contained program. The important habit is to predict what runs, inspect the actual output and distinguish the language rule from the particular example.

Before continuing, make sure you can explain the program to someone who has not seen it, including the line that changes its result.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: File Organizer →