1. Explain object-oriented analysis.
2. Explain the difference between object encapsulation, object inheritance and object composition.
3. Explain the purpose of the different types of methods for class development: constructors, mutators and accessors
4. Explain the purpose of attributes for the best practice of class development.
1)
In object oriented analysis approach every requirement we will organize arround objects.Here we integrates behaviours and states.In other programming languages those two are considered seperately.
Object-oriented programming has the concept of class which holds the data and methods.This depends on objects.With this it implemented the concept of dynamicness. Most important thing is that in object-oriented programming we have a chance of code reusability .With we can avoid the duplication of code.
________________________
2) Encapsulation :
Holding the variables and the methods which acts on those variables as a single unit is called Encapsulation.
The best example for this is a Class.
Which contains instance variables ,methods which acts on those variables.
Inheritance: Producing new classes from already existing classes is the concept of inheritance.Already developed class is called as Parent class or super class.Newly created class is called child class.
Suppose ,If a class(Person) is developed in java is having some instance variables and methods inside it.
Let‘s say another class(Student) which is also having some instance variables and methods which are common to the previous class.Again if we have to provide the same code in this class while developing the code we have to again write the same code in this class also.This results in duplication of code
Drawbacks :
1)This will consume the time while developing the same code again in another class
2)Chances of bugs occurring will increase as the size of the code increasing.
3)Time taken to test the code will increase.
4)Duplication of code increased in the classes.
To avoid these problems , we have to eliminate the duplicate code among related classes by using the concept of inheritance.By using this concept we can reuse the code which is present in another class .
public class Person()
{
private String name;
private String address;
//Methods
}
public class student extends Person()
{
private int id;
private int marks;
//Methods
}
Here we are creating the student class by extending From Person class.So that we can use the methods which are present in the Person() class.This will eliminate the duplication of the code.The advantage of this is developers can develop more code in less amount of time.hence productivity of the developer will be increased.
Composition :
In object oriented approach , an object comunicates with other object to use functionality and services provided by the other object. For this purpose we use Composition .It is one of the type of association established between two different classes.
_______________________
3)
Constructors :
A constructor is a method which is used to initialize the instance variables of the object. Instance variables are the variables (used to hold the data) available as seperate copy for each instance of class.
We have two types of constructors:
1.Default Constructor or Zero argumented constructor
2.Parameterized constructor
Default constructor is just like a method but this will be called and executed when ever we create an object to the class.Generally the use of default of constructor is to initialize the instance variables with default values.
Even if we didn’t provide the default constructor inside the class,During compilation of the program jvm will check whether our class is having default constructor or not.If we didn’t provide the default constructor then JVM will create the default constructor inside our class.
When ever we want to initialize the instance variables with new values every time we have to use parameterized constructor.Then at that time we no need to provide the default constructor.
If we provided the parameterized constructor then the JVM will not create the default constructor inside our class
___________________
Accessors and Mutators :
Generally it is recommended to declare the instance variables as private.
So we cant access those varibles directly to set the data to them(Assigning the data to them) or to access the data from them So we will take the help of the Accessor and Mutator methods.
If we want to modify the instance variables of the class then we have to provide the setters and getter methods.The setter methods is also called as mutator methods.By using this methods we can change the values of the instance variables.
If we want just to access the instance variables of the class then we can use these accessor methods.
Holding the data inside the variables and methods which are used to access or modify that data inside the variables is called as encapsulation(Or)Binding the data and methods which are used to access or mutate the data in a single class is called Encapsulation.
_______________________
4) The purpose of attributes is to hold the data . We generally call them as fields or varibles.we provide these attributes inside the class .Different objects can have different states (Different variables which are holding different values).
_______________________
1. Explain object-oriented analysis. 2. Explain the difference between object encapsulation, object inheritance and object composition....