Did you know ... Search Documentation:
Pack logtalk -- logtalk-3.86.0/manuals/_sources/faq/programming.rst.txt

.. This file is part of Logtalk https://logtalk.org/ SPDX-FileCopyrightText: 1998-2024 Paulo Moura <pmoura@logtalk.org> SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

.. _faq_programming:

Programming

:(ref:[102, 97, 113, 95, 112, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 95, 101, 105, 116, 104, 101, 114, 95, 112, 114, 111, 116, 111, 116, 121, 112, 101, 115, 95, 99, 108, 97, 115, 115, 101, 115])
:(ref:[102, 97, 113, 95, 112, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 95, 98, 111, 116, 104, 95, 112, 114, 111, 116, 111, 116, 121, 112, 101, 115, 95, 99, 108, 97, 115, 115, 101, 115])
:(ref:[102, 97, 113, 95, 112, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 95, 104, 105, 101, 114, 97, 114, 99, 104, 121])
:(ref:[102, 97, 113, 95, 112, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 95, 112, 114, 111, 116, 111, 99, 111, 108, 115, 95, 99, 97, 116, 101, 103, 111, 114, 105, 101, 115])
:(ref:[102, 97, 113, 95, 112, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 95, 99, 111, 109, 112, 111, 110, 101, 110, 116, 115])
:(ref:[102, 97, 113, 95, 112, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 95, 114, 101, 102, 108, 101, 99, 116, 105, 111, 110])
.. _faq_programming_either_prototypes_classes:

Should I use prototypes or classes in my application?

Prototypes and classes provide different patterns of code reuse. A prototype encapsulates code that can be used by itself and by its descendent prototypes. A class encapsulates code to be used by its descendent instances. Prototypes provide the best replacement to the use of modules as encapsulation units, avoiding the need to instantiate a class in order to access its code.

.. _faq_programming_both_prototypes_classes:

Can I use both classes and prototypes in the same application?

Yes. In addition, you may freely exchange messages between prototypes, classes, and instances.

.. _faq_programming_hierarchy:

Can I mix classes and prototypes in the same hierarchy?

No. However, you may define as many prototype hierarchies and class hierarchies and classes as needed by your application.

.. _faq_programming_protocols_categories:

Can I use a protocol or a category with both prototypes and classes?

Yes. A protocol may be implemented by both prototypes and classes in the same application. Likewise, a category may be imported by both prototypes and classes in the same application.

.. _faq_programming_components:

What support is provided in Logtalk for defining and using components?

Logtalk supports component-based programming (since its inception on January 1998), by using categories (which are first-class entities like objects and protocols). Logtalk categories can be used with both classes and prototypes and are inspired by the Smalltalk-80 (documentation-only) concept of method categories and by Objective-C categories, hence the name. For more information, please consult the :ref:categories_categories section and the examples provided with the distribution.

.. _faq_programming_reflection:

What support is provided in Logtalk for reflective programming?

Logtalk supports meta-classes, behavioral reflection through the use of event-driven programming, and structural reflection through the use of a set of built-in predicates and built-in methods which allow us to query the system about existing entities, entity relations, and entity predicates.