________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
SPDX-FileCopyrightText: 1998-2023 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.
________________________________________________________________________


% start by loading the design pattern sample implementations:

| ?- logtalk_load(design_patterns('creational/multiton/loader')).
...


% get a list of all named instances:

| ?- multiton::instances(Instances).

Instances = [i1, i2, i3]
yes


% verify that no named instance exists until is actually requested:

| ?- \+ current_object(i1), \+ current_object(i2), \+ current_object(i3).

yes


% request to the multiton class one of its named instances:

| ?- multiton::instance(i2).

yes

| ?- current_object(i2).

yes


% try to request an instance that is not a member of the named instances:

| ?- multiton::instance(foobar).

no

| ?- current_object(foobar).

no
