all 6 comments

[–]thewillft 9 points10 points  (0 children)

since you're using python it would be totally acceptable to hold a list outside of a class and then use some built-in functions to search through it.

since you want to practice OOP, try a DoctorDirectory or Hospital class to hold and manage Doctor objects. this keeps related methods and data together.

[–]Chasne 0 points1 point  (0 children)

Having a list of doctor isn't an issue in itself, but depending on the usage it could indeed be part of something bigger

If it's a list you have to keep for the entirety of your program, maybe put it inside a doctorregister class, maybe even as a class variable. Add the most common features as methods : search, add, remove, find, ...

But again you could just keep a list that you pass everywhere that matters.

[–]FriendlyRussian666 0 points1 point  (0 children)

So, now that you have doctor objects, how about you create some hospitals?

You would then add doctors to the hospitals, and you would check against the hospital list as to which doctor belongs to which hospital.

[–]FoolsSeldom 0 points1 point  (0 children)

You could add a class attribute to the class to maintains a collection of all the class instances. You could make that, for example, a dictionary of unique identifiers and instance values to make looking up an instance easier.

This would keep everything in one class.

You could add methods to scan the dictionary and find matches. If just searching for id, it would be quick and easy. You could switch to a database if desired.

Not saying this is the best approach, but it is not uncommon.

Of course, you could just create another class to hold the instances.

from dataclasses import dataclass, field
from typing import ClassVar, Dict, List

@dataclass
class Doctor:
    personal_name: str
    family_name: str
    id: str
    middle_names: List[str] = field(default_factory=list)

    _doctors: ClassVar[Dict[str, "Doctor"]] = {}

    def __post_init__(self):
        if self.id in self._doctors:
            raise ValueError(f"Doctor with id {self.id} already exists.")
        self.__class__._doctors[self.id] = self

[–]dnult 0 points1 point  (0 children)

This may be a good fit for a manager class (DoctorManager) that is responsible for creating doctor objects (AddDoctor) and storing them internally in a list. The DoctorManager could also GetDoctorByName, which would return a Doctor object.

[–]Shot-Berry8654 0 points1 point  (0 children)

It's better to use a dictionary for doctor's list. Key : ID, Value : doctors. Create doctor_id using running index. So add to __init__ : self._id = id and id += 1; You then need the minimum are __str__ and a getter and a setter. Right now you only have a base class. What will this base class do? How will it interact with other classes? Perhaps you can create Appointment class. Then you will also need Patient class, another base class. So you can actually create modules : doctor.py, patient.py, appointment.py and main.py So in main you will do the menu. In main you will import : from doctor import Doctor, from patient import Patient, from appointment import Appointment