Restrict ViewModel visibility to `internal` within feature modules

Đang mở
#1,921 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
kotlin
Lĩnh vực
mobile-dev

Hướng nghiên cứu

Tìm trong project các class @HiltViewModel và các khai báo ViewModel public, bắt đầu với ví dụ BookmarksViewModel. Kiểm tra các tham chiếu của từng ViewModel giữa các feature module trước khi thay đổi visibility; hoàn tất nghĩa là chỉ những ViewModels không được sử dụng bên ngoài module của chính chúng mới là internal và project vẫn biên dịch được.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

All ViewModel classes across the project are currently declared as public, even though they are only used within their respective feature modules. This can lead to unintended usages across modules and violates encapsulation principles.

Proposal

Change the visibility modifier of each ViewModel from public to internal if it is not used outside the module it belongs to.

This adjustment:

  • Prevents accidental access from other modules
  • Reinforces module boundaries
  • Keeps internal logic private to its domain
  • Makes the codebase more maintainable and intention-revealing
Example
// Current (public by default)
@HiltViewModel
class BookmarksViewModel @Inject constructor(...) : ViewModel() {
    ...
}

// Suggested
@HiltViewModel
internal class BookmarksViewModel @Inject constructor(...) : ViewModel() {
    ...
}
Ngôn ngữ chính
Kotlin
Star
22.1k
Fork
4.7k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của android/nowinandroid

Tất cả issue của android/nowinandroid

Issue tương tự

Thêm issue về Kotlin

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.