Python Forum
Single Responsibilty Principle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Single Responsibilty Principle
#1
I got to thinking about what ndc85430 said in one of my post, and was wondering if this would roughly fall along those lines.
Classes could be added or removed without affecting the others.
All classes could have a relation with the Register class or other class within the program.
Just trying to get a basic understanding.
Thanks for any input.

#! /usr/bin/env python3

class Register:
    def __init__(self):
        self.first_name = ''
        self.last_name = ''
        self.email = ''


class Email(Register):
    def __init__(self, email):
        print(f'Sending confirmation email to {email}')


class Display(Register):
    def __init__(self, first_name, last_name, email):
        print(f'Hello {first_name.title()} {last_name.title()}\nYour email is {email}')

# Initial registration
newuser = Register()
newuser.first_name = 'John'
newuser.last_name = 'Doe'
newuser.email = f'{newuser.first_name}.{newuser.last_name}@domain.com'

# Display the information. Can be changed without affecting registration
Display(newuser.first_name, newuser.last_name, newuser.email)

# Sending the confimation email
Email(newuser.email)

Sorry, I should have placed this in the news and discussions.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Messages In This Thread
Single Responsibilty Principle - by menator01 - Jun-28-2020, 01:55 PM
RE: Single Responsibilty Principle - by Yoriz - Jun-28-2020, 02:22 PM
RE: Single Responsibilty Principle - by ndc85430 - Jun-28-2020, 05:32 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020