0

I'am little confused about how business logic should be implemented using web services. For example, think about an education management application. There are simply students, teachers and courses. Now, the server side of the application may provide getStudents operation via a WSDL interface. This operation returns list of Student elements.

According to object oriented paradigm a class should have a certain responsibility. It should hide its internal state and one can reach its data only using its operations. But at the client side a Student class is only a data bag. There is no logic so no responsibility here.

Another problem is that there is no reference semantics at the client side. Normally, a student is associated with some courses. But in the implementation a Student object has list of Course objects or it may hold some identifier for courses.

Finally, using web services (by WSDLs) seem to convenient for access remote data but not for execute business logic remotely. Am I right, or do I miss something important about web services?

Edit:

My intent is implement business logic at server side. For example suppose that a have classes in server side like that:

class Student
{
  //some properties like name, courses, etc.
  double calculateGPA(); //calculates average grade using course credits.
  //other operations like getName()
}

class SchoolRepository
{
  List<Student> getStudents();
  List<Course> getCourses();
  //other operations
}

Now, I can create WSDL which provide SchoolRepository interface. So, client get list of students. But they cannot reach business logic implemented in calculateGPA() directly. I may provide another WSDL interface for that. But it breaks data and behavior encapsulation.

  • yes. you are missing the some points. Depending of the web service the implementation changes a lot. For example SOAP is a method invocation while in REST you are operation on a resource. – linuxunil Jan 3 '17 at 12:12
  • What do you want to do? What use-case are you struggling to cater for? I'm very confused at this question. – JᴀʏMᴇᴇ Jan 3 '17 at 14:13
  • @JᴀʏMᴇᴇ I want to implement business logic at server side. For example, I want to get list of students. Then, I want to learn their GPA which is a derived value (Student class has no GPA member at server side). Is it clearer? – Q Q Jan 3 '17 at 14:28
  • Nope, sorry. So, from the service's perspective, you want to expose 'GetStudents'. That's fine. Then you want to expose 'GetStudentGPA', no? – JᴀʏMᴇᴇ Jan 3 '17 at 14:47
  • @JᴀʏMᴇᴇ we can see that the OP is mixing SOAP(wsdl, remote function calls) with REST(resource oriented). Mayber the OP need to know about the differences between SOAP and REST. – linuxunil Jan 3 '17 at 14:56
2

Your example getStudents() is what is confusing you. I realize you've selected this as a simple example, but that's the problem. It is so simple in your mind you don't see any logic being applied.

Taken literally, you are going to return every student ever entered into the system since the beginning of time. Is there really a need for that? Does this include students who enrolled, but left the school before ever finishing one class? Do all the students have to be accepted? Have they graduated?

Once you start considering the real benefit of your application (it's not just a list of students and their coursework), you'll see where the logic is needed. Here are a few examples:

  • Enroll a student in a class, but check for prerequisites, conflicting classes, availability, faculty approval, etc.
  • Expell a student - create a workflow and notification process to get all the necessary approvals.
  • GetFullTimeStudentsByGradingPeriod(gradingperiod)- calculate the number of credit hours enrolled during the given period to determine full-time status.
  • AssignStudentCourseGrade(student, course) - Check if enrolled and is the user allowed to enter grades for this course.

If your application is nothing but a "skin" on a database, then you don't really hve much logic to worry about, but I think you're making a lot of assumptions that you'll soon learn will require logic to be performed by the service and not that application using the service.

1

You need to design an architecture and decide the overall responsibility of the front-end and the back-end. For example:

  • The front-end handles the presentation of the data, and the interactions with the user. The objects there are not responsible for behavior : they are only data transfer objects to be displayed. Eventually they could act as proxy for the server object.
  • The back-end manages the domain object and the data persistence. The service layer provides a facade for exposing application services over the web.

In this scenario you would have services like getStudent(id), getCourseCatalog(), and getStudentCourses(id). The front-end would not need to care for business logic, but only to display the data. Depending on user interaction it will have to call application services such as registerStudent(id, courseId) on the server.

Of course, there are plenty of other ways to do it. But having a mixed architecture, with some business logic performed on the front-end would be a bad idea : business logic needs more frequent access to the domain objects that are managed on the server, and latency numbers that every programmer should know suggest that this could be a performance bottleneck (not speaking of the unclear responsibilities).

I can only recommend you Martin Fowler's excellent book "Patterns of Enterprise Application Architecture" that addresses these kind of topics in a very clear and exhaustive way.

Another useful source of idea can be this website.

  • Yes, web services fit back-end and front-end architecture. But in my case, the clients aren't front-ends. Instead, they are stand alone applications which using web services from their business layers. In the use case above education ministry may be a client of school services. The client software may need a true Student class rather than a DAO. It might be better that the client has its own Student class and converts it web service's Student and vice versa. – Q Q Jan 4 '17 at 6:29
  • @QQ I see ! From what you tell I see two alternatives: 1) build your client using the EAA pattern of "active record" and consider the service that provide them as data source (i.e replacing a database); 2) build your application as another service and use a microservice approach. – Christophe Jan 4 '17 at 7:29
0

Web services is just the way parts of your application communicate with the core business modules. It has nothing to do with business logic implementation it self. You should always define processes on BL (ex. GetStudentCourses, AddStudentCourse etc) and expose them depending on the architecture. As web services if remote app, direct use of service layer if web app etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.