Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

update decoupled-example with abstraction layer#770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
fanqingsong wants to merge1 commit intoets-labs:master
base:master
Choose a base branch
Loading
fromfanqingsong:master

Conversation

fanqingsong
Copy link

Hi
The decoupled-example code is good, but it lack one important component of DIP rule(https://www.cs.utexas.edu/users/downing/papers/DIP-1996.pdf)
I mean the "Abstraction" layer which can help make "user" and "photo" compliant to abstract classes of their own and "analytics" depends on these abstract classes, and even for "analytics" can be extracted one abstract class, then formain.py (the top-level service aggregation) can only depend on these three abstract class, finally "ApplicationContainer" is for connecting the embodied containers("user", "photo", "analytics") tomain.py.
The update code is better to demostrate DIP rule for developer.

I also update docs part.

Please check.
Thanks.

Copy link
Contributor

@ZipFileZipFile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This PR needs some addition work.

from ..user.repositories import UserRepositoryMeta


class AggregationServiceMeta(metaclass=abc.ABCMeta):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
classAggregationServiceMeta(metaclass=abc.ABCMeta):
classAggregationService(metaclass=abc.ABCMeta):

Meta suffix might give it a wrong impression that this is a metaclass. Let's avoid ambiguous naming.

self.user_repository = user_repository
self.photo_repository = photo_repository

class AggregationService(AggregationServiceMeta):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
classAggregationService(AggregationServiceMeta):
classAggregationServiceImpl(AggregationService):

or

Suggested change
classAggregationService(AggregationServiceMeta):
classMemoryAggregationService(AggregationService):

See comment above. This way it would be much more clear about implementation specifics of theAggregationService interface.

Comment on lines +12 to +14
def __init__(self, user_repository: UserRepositoryMeta, photo_repository: PhotoRepositoryMeta):
self.user_repository: UserRepositoryMeta = user_repository
self.photo_repository: PhotoRepositoryMeta = photo_repository
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Interfaces generally has no__init__, it's an implementation detail.

Suggested change
def__init__(self,user_repository:UserRepositoryMeta,photo_repository:PhotoRepositoryMeta):
self.user_repository:UserRepositoryMeta=user_repository
self.photo_repository:PhotoRepositoryMeta=photo_repository

Comment on lines +58 to +68
│ ├── abstraction
│ │ ├── __init__.py
│ │ ├── analytics
│ │ │ ├── __init__.py
│ │ │ └── services.py
│ │ ├── photo
│ │ │ ├── __init__.py
│ │ │ └── repositories.py
│ │ └── user
│ │ ├── __init__.py
│ │ └── repositories.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

For such simple app example, I'd move everything intointerfaces.py to keep app structure from bloating.

@abc.abstractmethod
def get_photos(self, user_id):
"""Must be implemented in order to instantiate."""
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
pass

Coverage report treatspass as a code. Which never executes forabstractmethods.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ZipFileZipFileZipFile requested changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@fanqingsong@ZipFile

[8]ページ先頭

©2009-2025 Movatter.jp