不使用类时减少耦合

时间:2019-03-01 11:39:29

标签: python

我已经编写了一个代码,该代码可以从一个系统解析XML并将输入写入Redshift。为此,我有以下文件:

handler.py (a simple function that requires social_network.py)

queries.py (nothing here, only attributes to store sql queries
because they are big and I dont want to write on social_network.py)

redshift.py (a wrapper for psycopg2 that has 2 functions - create 
conn and run queries)

social_network.py:a few methods to handle XML, normalize it using pandas, 
send it to S3 and call some redshift commands - this file requires 
redshift.py and queries.py

我不使用类,仅使用函数。

在文件social_network.py中,我的所有功能都很小,并且具有单一的职责,例如接收数据和调用redshift来存储,接收数据和使用熊猫进行解析等。此文件具有处理{{ 1}},所有必需的功能都在此文件中。

其他键:我所有的功能都是纯函数,我尝试使所有属性保持不变。

重点是:这个项目非常简单,现在我只能使用social_network应用程序。我不确定是否可以将代码称为低耦合,因为文件SocialNet具有从social_network.pyqueries.py导入的文件。

写这样的代码是一种好习惯:

redshift.py

当这个项目发展壮大时,我可能会重构以实现一些类和继承,但是现在看不到使用类的任何意义。

0 个答案:

没有答案