<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def construct(cls, name: str, declared_fields: typing.List[tuple]):
 """ Utility method packaged along with the factory to be able to construct Request Object classes on the fly. Example: .. code-block:: python UserShowRequestObject = Factory.create_request_object( 'CreateRequestObject', [('identifier', int, {'required': True}), ('name', str, {'required': True}), ('desc', str, {'default': 'Blah'})]) And then create a request object like so: .. code-block:: python request_object = UserShowRequestObject.from_dict( {'identifier': 112, 'name': 'Jane', 'desc': "Doer is not Doe"}) The third tuple element is a `dict` of the form: {'required': True, 'default': 'John'} * ``required`` is False by default, so ``{required: False, default: 'John'}`` and \ ``{default: 'John'}`` evaluate to the same field definition * ``default`` is a *concrete* value of the correct type """

        # FIXME Refactor this method to make it simpler

        @classmethod
        def from_dict(cls, adict):
            """Validate and initialize a Request Object"""
            invalid_req = InvalidRequestObject()

            values = {}
            for item in fields(cls):
                value = None
                if item.metadata and 'required' in item.metadata and item.metadata['required']:
                    if item.name not in adict or adict.get(item.name) is None:
                        invalid_req.add_error(item.name, 'is required')
                    else:
                        value = adict[item.name]
                elif item.name in adict:
                    value = adict[item.name]
                elif item.default:
                    value = item.default

                try:
                    if item.type not in [typing.Any, 'typing.Any'] and value is not None:
                        if item.type in [int, float, str, bool, list, dict, tuple,
                                         datetime.date, datetime.datetime]:
                            value = item.type(value)
                        else:
                            if not (isinstance(value, item.type) or issubclass(value, item.type)):
                                invalid_req.add_error(
                                    item.name,
                                    '{} should be of type {}'.format(item.name, item.type))
                except Exception:
                    invalid_req.add_error(
                        item.name,
                        'Value {} for {} is invalid'.format(value, item.name))

                values[item.name] = value

            # Return errors, if any, instead of a request object
            if invalid_req.has_errors:
                return invalid_req

            # Return the initialized Request Object instance
            return cls(**values)

        formatted_fields = cls._format_fields(declared_fields)
        dc = make_dataclass(name, formatted_fields,
                            namespace={'from_dict': from_dict, 'is_valid': True})
        return dc