CSE 300 Software Engineering Object Oriented Programming and
CSE 300 - Software Engineering Object Oriented Programming and Design CSE/ECE-5 XX
CSE 300 - Software Engineering Discussion Items • OOP relations – Has-a relation • OOP features 2 by Manish Shrotriya
CSE 300 - Software Engineering Has-a Relations
CSE 300 - Software Engineering Has-a Relation types • Composition – A is said to be composed of B implies that A cannot exists without B and B’s existence without A would be meaningless. • Aggregation – A having aggregation relation with B implies A’s existence depends on B. B can exist without A. 4 by Manish Shrotriya
CSE 300 - Software Engineering Has-a Relation types • Association – A is said to be associated with B if B is a non essential ingredient for A’s state. – Association could be: • One to one • One to many • Many to Many 5 by Manish Shrotriya
CSE 300 - Software Engineering Example • Person { Body body; Person mother; Person father; List<Person> siblings; Person spouse; List<Person> offsprings; } • Relations are essential part of OOP as they help us to determine “ready for business” state for an object. 6 by Manish Shrotriya
CSE 300 - Software Engineering What is OOP? 7 by Manish Shrotriya
CSE 300 - Software Engineering OOP Features (not the requirement) 1. Polymorphism: a. One object having multiple is-a relation is polymorphism b. OO language generally supports polymorphism by inheritance where a new object type can be created by “inheriting” other types c. In some cases, an object can simultaneously exhibit all or some of its forms, while in some context it can exists as one of it forms, exclusively. d. In java when a class( say A) extends another class or another interface then objects of class A become polymorphic. 8 by Manish Shrotriya
CSE 300 - Software Engineering OOP Features (not the requirement) 1. Encapsulation: a. Every object has a state made of all field values. b. Object’s type can choose to keep its state completely or partially c. d. e. f. hidden from any other object. This ability is called Encapsulation. Often all OO language provide this facility using access modifier. Java has private, protected, default and public. Thumb rule for Encapsulation Usage: i. Object should only allow required properties accessible. It helps keep your design flexible as it reduces dependence on the object’s internal structure. 9 by Manish Shrotriya
- Slides: 9