Results 1 to 6 of 6

Thread: Behaviour of class in OOPs

  1. #1
    Join Date
    Dec 2009
    Posts
    263

    Behaviour of class in OOPs

    Hello,
    I have a little problem in understanding the class behavior in the Object oriented programming. I have two classes Employee and Workman have exactly the same behavior and properties, the only difference being their type (one worker and another employee).
    I have two question on this
    1 - Either I create a Person class which will inherit the classes Employee and Worker.
    2 - Either I create a class Person with a property which will be named in more Type Personnel which may contain [Employee, Worker], to distinguish a person an individual employee and worker.
    Which approach is best in your opinion? Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Behaviour of class in OOPs

    Hello,
    I think I would go with the following line in your post
    1 - Either I create a Person class which will inherit the classes Employee and Worker.
    I will explain you with a small example, suppose you have a car class, your car class which will inherit the class Truck, Sedan, Station Wagon, etc. I hope you are understanding the concept I am trying to explain. I advice you to read some basic documentation on java and be clear with the basic that is the java core.

  3. #3
    Join Date
    Nov 2009
    Posts
    330

    Re: Behaviour of class in OOPs

    Hello,
    For me, what can make the choice between two solutions is really whether an employee and a worker have differences other than being an employee and a worker, like other attributes (properties) or other methods (building). But in the presentation that you do, the only difference is that term in nature. It is not at all in the case of car. So for me it would be an attribute type of person. If you look at the API standard, it was full of cases where this implementation with a type attribute is implemented.

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Behaviour of class in OOPs

    Hi,
    I agree with the above post, small example to illustrate: I have a worker - some person - which is defined
    Code:
    Worker example = new Worker();
    And exampleworker is working really well, so he becomes an employee. It is not with inheritance. Hence this is true if you consider the above post. It's true that if there is no evolution possible for a worker to become employed, my example falls into the water. I guess you got the point here.

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Behaviour of class in OOPs

    Hello,
    By cons as I see no difference between an employee and a worker. It is perhaps only one class employees and add more types of employees: Worker, Secretary, Engineer. Unless there are people who are not employees. In this case, it is better to create a class person with a sub-class employees (an employee is paid ) And each employee type.

  6. #6
    Join Date
    Nov 2009
    Posts
    333

    Re: Behaviour of class in OOPs

    Hello,
    I have an example with me, see if this helps you.
    Code:
    Public Interface wkr {
        + Set / get
    }
     
    Public Interface emp {
        + Set / get
    }
     
    Public class Person implements wkr, emp {
        - Attributes of'forums
        + Set / get
         public emp evl () (
             if (this instanceof emp) (
                 throw new evlImpossibleException ();
             )
             emp emp = new Person ();
             employe.setX (this.getX ());
             ....
             return emp;
         )
    
         Public wkrs regression () (
             if (this instanceof wkr) (
                 throw new RegressionImpossibleException ();
             )
             wkr w= new Person ();
             ouvrier.setX (this.getX ());
             ....
             return workers;
         )
    )
    
    public class Test (
        public void test () (
            wkr w= new Person ();
            emp emp = new Person ();
            ...
            emp e = ouvrier.evolution ();
            ....
        )
    )

Similar Threads

  1. How to handle employee's behaviour ?
    By Grayson in forum Education Career and Job Discussions
    Replies: 3
    Last Post: 18-11-2010, 01:30 AM
  2. Oops management Date and TimeZone
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 03:40 AM
  3. What does OOPS concepts comprises?
    By abigial_i in forum Software Development
    Replies: 3
    Last Post: 08-12-2009, 09:24 AM
  4. Whats the best way to learn oops
    By jaynok in forum Software Development
    Replies: 2
    Last Post: 29-04-2009, 08:08 PM
  5. OOPS Concepts
    By suneel_g in forum Software Development
    Replies: 3
    Last Post: 22-12-2008, 12:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,518,180.77929 seconds with 17 queries