Đang chuẩn bị liên kết để tải về tài liệu:
Object Oriented Programming (17)

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

CSC241: Object Oriented Programming. Lecture No 17. 1 Previous lecture.•. Multiple inheritance. – Example program: employ and student class.•. Constructor in multiple inheritance. – Example program.•. Composition. 2 Today’s lecture.•. Example program – inheritance.•. Relationship between class. – Association. – Aggregation. – Composition.•. Memory management. – String class 3 Example programProblem statement.•. Various situations require that pairs of numbers. be treated as a unit. For example, each screen. coordinate has an x (horizontal) component and. a y (vertical) component•. Derive a new class pairStack from Stack that. allow to store pair variables on a stack using. a single call to a push(). – push(st); // st is a structure type variable.•. retrieve using a single call to pop() function,. Go to program. 4 Association.•. It is a simple connection or channel between. classes.•. It is a relationship where all objects have their. own lifecycle and there is no owner.•. Example: Department and student. – Multiple students can associate with single. department. – Single student can associate with multiple. departments. – No ownership. – Both can create and delete independently 5 Aggregation.•. It is a form of association where all object have. their own lifecycle but there is a ownership like. parent and child.•. Represents as “has a” relationship.•. Implementation details:. – Use pointer variables that points to object of other. class. – Can use a reference variables that points to object of. other class. – Not responsible for creation/destruction of subclass. 6 Cont •. Example: Employee and Company. – A single employee cannot belong to multiple. company – If we delete the company, Employee object will not. destroyEmployee e(6, “ali”);. Company C(“MS”, c. nam. e. &e); ali ID 6. e. nam. *emp ali. Go to program e. 7 Composition.•. It is a specialize form of aggregation•. It is a strong composition.•. Parent and child objects have coincident. lifetimes.•. Child object dose not have it's own lifecycle.•. If parent object gets deleted, then all of it's child. objects will also be deleted 8 Cont•. Composition gives us 'part-of‘ relationship.•. It is a stronger form of aggregation.•. It has all the characteristics of aggregation plus. two more. – The part may belong to only one whole. – The life time of the part is same as life time of the. whole.•. For example, it make sense to say that an. engine is part-of a car – The lifetime of the part (Engine) is managed by the. 9. whole (Car), in other words, when Car is destroyed, Cont•. Implementation details. – Use normal member variables. – Can use p

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.