TINAELLIS\Cybersecurity

Welcome to my blog!


Techniques for Designing Classes

Back

Steps for Designing Classes

1 - Find the Classes in the problem:

2 - Identify the Class’s Responsibility:

3 - Design a UML Diagram Unified modeling language (UML) diagram:

Example

Attributes and Methods Identified and Separated

What must the class know (attributes):

What must the class do (methods):

Create UML Diagram

------------------------------
        Customer                # class name
------------------------------
__name
__address
__phone                         # class attributes
------------------------------
__init__(name, address, phone)
set_name(name)
set_address(address)
set_phone(phone)
get_name(name)
get_address(address)
get_phone(phone)                # class methods
------------------------------

Translate Information into Class

class Customer:
    def __init__(self, name, address, phone):
        self.__name = name
        self.__address = address
        self.__phone = phone

    def set_name(self, name):
        self.__name = name

    def set_address(self, address):
        self.__address = address

    def set_phone(self, phone):
        self.__phone = phone

    def get_name(self):
        return self.__name

    def get_address(self):
        return self.__address

    def get_phone(self):
        return self.__phone