DEV Community

Peter + AI
Peter + AI

Posted on

πŸš€ Understanding Uniface 10.4 Public Declarations: Making Components Accessible

πŸ“ This blog post was created with AI assistance to help explain Uniface concepts in simple terms.

What is the "public" Keyword? πŸ”

The public keyword in Uniface 10.4 is like giving someone a key to your house 🏠. It makes operations and handles available for other components to use. Without this keyword, your code stays private and can't be accessed from outside.

Different Ways to Use Public πŸ“‹

1. Public Operations πŸ› οΈ

A public operation is a function that other components can call. Think of it like a public telephone - anyone who knows the number can call it.

public operation getAccounts
  // Your code here
end
Enter fullscreen mode Exit fullscreen mode

2. Public Handles 🎯

A handle in Uniface is like a pointer or reference to data. Making it public means other components can access this data.

{public} handle ParameterName : Direction
Enter fullscreen mode Exit fullscreen mode

3. Public Web Operations 🌐

When you add public web, you're saying "browsers and web clients can trigger this operation." It's like putting a doorbell on your front door that visitors can ring.

operation HelloWeb
public web
  // This can be called from a web browser
end
Enter fullscreen mode Exit fullscreen mode

4. Public SOAP Operations 🧼

SOAP (Simple Object Access Protocol) is a way for different software systems to talk to each other over the internet. public soap makes your operation available as a web service.

operation MyWebService
public soap
  // This can be called by SOAP clients
end
Enter fullscreen mode Exit fullscreen mode

Important Rules to Remember ⚠️

  • System triggers (special built-in functions) cannot be declared as public web ❌
  • If you try to make a system trigger public web, Uniface will show an error and won't compile your component 🚫
  • You can use public operations and handles in all component types βœ…

Real-World Example πŸ’‘

Imagine you're building an online banking system:

// This operation can be called by other Uniface components
public operation calculateInterest
  // Calculate interest for an account
end

// This operation can be called from a web page
operation checkBalance
public web
  // Show account balance on a webpage
end

// This operation can be called by external systems via SOAP
operation transferMoney
public soap
  // Transfer money between accounts
end
Enter fullscreen mode Exit fullscreen mode

Why Does This Matter? πŸ€”

The public keyword is essential for:

  • Component Integration - Different parts of your application can work together πŸ”—
  • Web Development - Creating web pages that respond to user actions πŸ–±οΈ
  • API Development - Building services that other systems can use πŸ”Œ
  • Code Reusability - Writing code once and using it in multiple places ♻️

Summary πŸ“

The public keyword in Uniface 10.4 is your gateway to making components accessible. Whether you're building internal integrations, web applications, or external APIs, understanding when and how to use public declarations is crucial for effective Uniface development. Remember to choose the right type of public declaration based on how you want your code to be accessed! 🎯

Top comments (0)