Overview
The Contact Management System is a console-based application built with Python that allows users to register, search, edit, and delete contacts. It demonstrates object-oriented programming principles, Python data structures, and JSON persistence. Key Features:- Contact registration with validation
- Flexible search (by name or phone)
- Contact editing and deletion
- JSON persistence
- Console-based menu interface
- Comprehensive unit testing (22/22 tests passing)
- Python 3.7+
- Standard libraries:
json,os,unittest - No external dependencies
Project Structure
Architecture
Contact Class
TheContact class represents a single contact with encapsulation using properties:
- Encapsulation: Private attributes with property decorators
- Validation: Setters validate non-empty values
- Serialization:
to_dict()andfrom_dict()methods for JSON conversion - String representation:
__str__()and__repr__()methods
ContactManager Class
TheContactManager class handles all contact operations and persistence:
agregar_contacto(): Add new contact with duplicate phone validationeditar_contacto(): Update contact informationeliminar_contacto(): Delete contact with confirmationbuscar_por_nombre(): Partial, case-insensitive name searchbuscar_por_telefono(): Exact phone search_cargar_contactos(): Load contacts from JSON on startup_guardar_contactos(): Save contacts to JSON after modifications
Usage
Installation
Menu Interface
Example Usage
Adding a contact:Testing
The project includes comprehensive unit tests covering:- Contact creation and validation
- Property setters and getters
- Contact serialization (to_dict/from_dict)
- ContactManager operations (add, edit, delete, search)
- JSON persistence
- Error handling and edge cases
Data Persistence
Contacts are stored in JSON format:- Automatic loading on startup
- Automatic saving after each modification
- UTF-8 encoding for special characters
- Pretty-printed JSON (indent=2)
- Error handling for file operations
Key Features
1. Contact Registration
- Validates all fields are non-empty
- Prevents duplicate phone numbers
- Automatic data persistence
2. Flexible Search
- By name: Partial match, case-insensitive
- By phone: Exact match
- Returns single contact or list of results
3. Contact Editing
- Edit name, email, or address
- Phone number is immutable (used as unique key)
- Option to keep existing values
4. Safe Deletion
- Confirmation prompt before deletion
- Clear feedback to user
5. Data Validation
- Empty field validation
- Duplicate phone number prevention
- Property-based encapsulation
Best Practices Demonstrated
-
Object-Oriented Design
- Clear separation of concerns (Contact vs ContactManager)
- Encapsulation with private attributes and properties
- Single Responsibility Principle
-
Data Validation
- Input validation at multiple levels
- Meaningful error messages
- Type hints for better code clarity
-
Persistence
- Automatic save/load operations
- JSON serialization with custom methods
- Error handling for file operations
-
Testing
- Comprehensive unit test coverage
- Test isolation with temporary test files
- Both positive and negative test cases
-
User Experience
- Clear menu interface
- Helpful prompts and feedback
- Confirmation for destructive operations
Technical Highlights
File:~/workspace/source/001_A2/PROYECTO/contact.py:15-23
~/workspace/source/001_A2/PROYECTO/contact_manager.py:47-54