Hi chaps, what do we define as a client of a class please? I keep reading about "clients of a class" but I don't understand what that means. Maybe it is better to have some examples: take the following 2 files:

//Employee.java
public class Employee{
    public static void main(String[] args){
        EmployeeClass employee1 = new EmployeeClass("your name 1", "your surname 1", 0.0);
        System.out.println("Printing values '1' initialized by the constructor.");
        System.out.printf("Name:%s ", employee1.getName());
        System.out.printf("\nSurnname:%s ", employee1.getLastName());
        System.out.printf("\nSalary:" + employee1.getSalary());

        EmployeeClass employee2 = new EmployeeClass("your name 2", "your surname 2", 0.0);
        System.out.println("\n\nPrinting values '2' initialized by the constructor.");
        System.out.printf("Name:%s ", employee2.getName());
        System.out.printf("\nSurnname:%s ", employee2.getLastName());
        System.out.printf("\nSalary: " + employee2.getSalary());

        //setting the values of the instance variables of first employee
        employee1.setName("John");
        employee1.setLastName("Smith");
        employee1.setSalary(19000.50);

        //getting the values of the instance variables of first employee
        System.out.println("\n\nPrinting the values of first employee's details after having set them");
        System.out.printf("Name:%s ", employee1.getName());
        System.out.printf("\nSurnname:%s ", employee1.getLastName());
        System.out.println("\nSalary: \u00A3" + employee1.getSalary());
        //increase 10% salary
        System.out.print("\na 10% rise will give a new salary of \u00A3" + employee1.salaryIncrease()); 

        //setting the values of the instance variables of second employee
        employee2.setName("Michael");
        employee2.setLastName("McWry");
        employee2.setSalary(23000.50);

        //getting the values of the instance variables of second employee
        System.out.println("\n\nPrinting the values of second employee's details after having set them");
        System.out.printf("Name:%s ", employee2.getName());
        System.out.printf("\nSurnname:%s ", employee2.getLastName());
        System.out.println("\nSalary: \u00A3" + employee2.getSalary());
        //increase 10% salary
        System.out.print("\na 10% rise will give a new salary of \u00A3" + employee2.salaryIncrease() + "\n");  
    }
}

SO which one is the client of which class please?
thanks

and this

//EmployeeClass.java
public class EmployeeClass{ 
    private String firstName;
    private String lastName;
    private double salary;

    //constructor taking 3 parameters
    public EmployeeClass(String name, String surname, double money){
        firstName = name;
        lastName = surname;
        salary = money;
    }

    //setters to set the instance variables
    public void setName(String name){
        firstName = name;
    }
    public void setLastName(String surname){
        lastName = surname;
    }
    public void setSalary(double money){
        if(money >= 0.0){
            salary = money;
        }
    }

    //getters to get the values back
    public String getName(){
        return firstName;
    }
    public String getLastName(){
        return lastName;
    }
    public double getSalary(){
        return salary;
    }

    //salary rise of 10%
    public double salaryIncrease(){
        salary += ((salary / 100) * 10);
        return salary;
    }
}

I'm not familiar with the term "client" used this way; that usually indicates some kind of network connection to me. For what I think you're asking, I usually use "consumer"--that is, a consumer of class A is any class B that uses class A.

If that's what we're talking about, then your Employee class is a consumer/client of EmployeeClass because the former uses the latter, but not the other way around.

Does that make sense?

I thought the term client was quite widespread (they use it often in the book I am reading http://www.deitel.com/Books/Java/JavaHowtoProgram9e/tabid/3622/Default.aspx).
What you say makes sense, but i have alse heard "client of an object" as in a class that calls the object methods, so I assume in this case it will be EmployeeClass because it uses the methods of the Employee class

by "client" what iv come to understand is the main method that runs classes and its methods in a particular fashion , to get a particular job done.

u might hear terms like "test client" as such as well... they are basically a tester class with just the main method , and uses many other classes for doing some work.

A client is someone or something that uses some services. Servers naturally have clients, and sometimes the word "client" means some specific technical thing, but it will always be a thing that is on the outside of whatever you are talking about using the services that are being discussed. If you were talking about an email server, the clients would be people or computers accessing emails remotely.

If you have some class and someone talks about a client of that class, that naturally means whoever is calling the methods of the class. Often when you are designing a class you don't care how or when the methods will be called, as long as the rules are followed. The client could be a main method, it could be some other method, or it could be many methods spread across many classes. In any case, you can just call it a client when you don't care to be more specific about who will be using the class.

ok thanks guys, much clearer now!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.