Head on over to page 397 of the tutorial for possibly the most important lesson in that document!
Okay, that's just my opinion. But I think object-oriented programming is important to WinDev for the same reason it's important to Clarion: OOP can save you from the greatest danger of these two products.
And that danger is: embedded code!
Yes, the thing that makes both Clarion and WinDev incredibly productive, a ready-made application framework with places to insert your custom code, is also the biggest problem with both environments. I'll stick to the WinDev version of my argument here.
Think of your application as having two main components. One, the larger in terms of code size, is the stuff WinDev creates for you based on your input in designing windows, queries, reports, etc. All of those things are commodities: you've essentially purchased them from PC Soft and configured them the way you want. But by definition a commodity is something that's readily available, not a single thing that provides unique value.
So what does give your application unique value to your customers? It's the business logic, the code that models how your customers actually do business.
The most convenient way to implement business logic in a WinDev application is to write your code right into the appropriate slot in the code editor.
It's also, I believe, the worst possible way to implement business logic. Code written right into the middle of a WinDev application:
- isn't reusable
- can't be tested in isolation
WinDev does have some really cool build-in testing capabilities, which is a wonderful thing. But testing business logic in situ is much more difficult than testing business logic that can be isolated into a class or set of classes.
While you can achieve some measure of testability by embedding your code right in the user interface (UI) code, you can't reuse that code; your only option is to cut and paste, which leads to a maintenance nightmare when 11 different versions of some block of code all need the same bug fix or new feature.
Isolating your business logic has other benefits as well. It's easier to identify, document and understand business logic when it isn't scattered throughout an application. And if at some point in the future you need to port to a new platform, it's the business logic that will make the trip, not the UI code. And although there are always differences between languages and platforms, non-UI object-oriented code is among the easiest kinds of code to port.
Info | ||
---|---|---|
| ||
No, you don't absolutely have to implement your business logic using objects. You can use procedures, although you'll have a much more difficult time of it. Object-oriented programming has been around for roughly half a century. It's not the answer to every situation, but it's an exceptionally effective way to model most business logic. |
Creating a class
As far as I know the only way to create a class in WinDev is via the Project Explorer. You can either right-click on the Classes node and choose New Class or you can click on the Create button and choose New Class.
Once you've created a class you'll see something like this:
You can type in new variables into the class declaration. To add a new method you need to make sure the class is highlighted in the project explorer, then use the right-click menu or the Create button to add a new method.
As with just about every other WinDev program element, classes are stored as binary files. I'm not a huge fan of this, because it precludes using any other text editor as well as sharing readable files via sites such as GitHub. You can, however, import those binary class files.
Next week I'll continue looking at WinDev's OOP implementation and I'll look at WinDev's unusual approach to passing parameters and returning values.