Chào mọi người, hiện tại em đang làm bài tập về oop. em có data mẫu từ 1 file csv, trong đó có các trường: số báo danh, điểm toán, điểm lý, điểm hoá, điểm văn, điểm sử, địa, gdcd. Đề yêu cầu sử dụng OOP để quản lý môn học thì em có nên tách ra thành nhiều class hay chỉ 1 class là được ạ. Em cảm ơn mọi người.
Hỏi về lập trình hướng đối tượng
thường khi người ta phân vân, có nghĩa là có thể lựa chọn, hoặc nói cách khác là xác định có khả năng làm được bằng nhiều cách
còn bạn đưa ra 2 cách, thì bạn đã nghĩ ra được chia nhiều class làm như nào chưa?
Tách ra nhiều Class là tách ra kiểu gì ??
Một Class chứa các thuộc tính : số báo danh, điểm toán, điểm lý, điểm hoá, điểm văn, điểm sử, địa, gdcd…
Hay tách ra kiểu gì ??
Quản lý môn học là quản lí kiểu gì …Mỗi một số báo danh là là một đối tượng chứa các giá trị là : điểm toán, điểm lý, điểm hoá, điểm văn, điểm sử, địa, gdcd…Hay như nào ???
1 class. Chung quy lại class là một khuôn mẫu chứa các thuộc tính và phương thức của đối tượng. Từ class đó chúng ta có thể tạo object, cũng có thể hiểu là một instance(thể hiện) thông qua từ khóa new.
Cú pháp Classname = new Classname(); -> Có thể điền các parameter phù hợp với constructor đã được định nghĩa trong Class
Bonus thêm: từ khóa new được sử dụng để khởi tạo đối tượng (yêu cầu JVM cấp phát bộ nhớ cho đối tượng đó, và đối tượng đó được lưu trong bộ nhớ Heap)
Bạn nên học lại OOP kĩ vì rất quan trọng cho một Java dev và cũng đừng quên là mày mò tìm hiểu về Java Architecture
OOP is the way of seeing a problem or thing as an object, and from that object view, the problem is broken down into different isolated parts so that it can be solved satisfactorily.
The transformation of a problem into an object is called object-oriented, or in other words, a bird’s eye view of an object. A bird’s eye view gives you the complete and comprehensive view of that object.
The separation and isolation of a problem (or thing) into different solvable parts is called programming in OO (hence OOP), which is nothing but a collection of different methods (in the old way: functions or procedures), each dealing specifically with a single part of a problem or thing. Or in other words, a mouse view. A mouse view gives you close proximity to different parts of an object (or problem).
OOP is therefore an individual intuition and cannot be categorized into any schemas. It is like a poem that cannot be categorized into any schemas. Otherwise, it is not a poem. In the same way, OOP cannot be classified into one or more classes, but depends on the bird’s eye and mouse view.
You have a CSV file with various fields. The bird’s eye view shows only 1 object. The mouse view shows you numerous fields that are either independent or dependent on each other. From the views, you have to decide what is the best way to do to solve the problem (CSV Object).
Ask around for solutions is not the best way to become an average IT developer and not as an OOP either.