OOPS - Determine the entities from the problem definition. Identifying real life things/entities.
- Inheritance
- Encapsulation
- Polymorphism
Abstraction - Mechanism of focusing on the similarities & ignoring the differences to define class.
Class diagram-
name
------
Data member
-------------
Member Function
Objects- Instance of a class - Identity, Behavior, State.
- Difference of Abstraction (analysis level- Identifying classes) Vs Encapsulation (design level-define the class structure- data members & member functions in the same capsule)
- Inheritance- Deriving /creating a new class from the base/ existing class.
Employee -- Parent class
^
|
Manager -- Child class
- Polymorphism - static and dynamic
Dynamic or run time polymorphism - Function over-riding, using base class reference.
Data members should not be accessible outside the class. So, usually are private but then cannot use in the derived class. So, make it protected . So that they can be used in the derived clases.
To access them from outside, use property- Getters & Setters-
Trivia Info-
- To override any method, the method in the base class should be virtual.
- When assigning value to a data member via argument of a method, the data member should be prefixed with "this."
- the base constructor is referred to as 'base' in the constructors in the derived class. Same as super in java.
- e1==e2 ---> Checks the Reference Vs e1.Equals (e2) - Checks the values.
foreach (Employee e in emplist)
e.cal_sal();
foreach - the type of the list has to be mentioned.
Abstract class- not to allow instantiating, only derived class can instantiate.
Interfaces - for multiple inheritance - programming by contract - define the interface.
Sealed class - classes cannot be inherited, same as final in java, opposite of abstract class.
Association (Linking) of different classes - Aggregation & Composition.
difference of aggregation and composition>
- Aggregation - Grouping of classes- like Library and Book--> part of the whole
- Composition - Strong Aggregation-Interdependent- Car & partContents of the whole.
Inner class - a class within a class.
Exception - Run time error - use the try - catch block to avoid system crashes.
try {}
catch (Exception ex){
Console.WriteLine(ex.Message);
}
class myException :Exception {
.........
}
No comments:
Post a Comment