Hiding the details

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Hiding the details

Beitrag von ayushmaan_jain »

Hi,

How can I achieve the following scenario :

Let's say I am using any 3rd party library for drawing image.
But I want to hide any class/interface of this 3rd party library from my application's public interface. How can I do this ?

Regards,
SJ

junaidmohiuddin
Neuling
Neuling
Beiträge: 9
Registriert: 18. Jun 2015 13:05

Re: Hiding the details

Beitrag von junaidmohiuddin »

Hi,

As per my knowledge you can achieve this by using the Builder Pattern


Regards,
Junaid

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Re: Hiding the details

Beitrag von ayushmaan_jain »

It will be highly appreciable if you could give a explanation of using "builder" pattern for this kind of design problems.

Banashri
Windoof-User
Windoof-User
Beiträge: 25
Registriert: 19. Dez 2013 02:55

Re: Hiding the details

Beitrag von Banashri »

Why builder?
In my opinion, it can be done using Command design pattern where invoker and receiver (3rd party application) are totally decoupled. Command is - DrawImage.
Correct me if I am wrong.

junaidmohiuddin
Neuling
Neuling
Beiträge: 9
Registriert: 18. Jun 2015 13:05

Re: Hiding the details

Beitrag von junaidmohiuddin »

Hi

I am really very Sorry i mean Bridge Pattern :)
Well by using the Bridge Pattern you can hide the implementation inside the abstraction .So in this way you can hide the implementation details from the client .

Regards
Junaid

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Re: Hiding the details

Beitrag von ayushmaan_jain »

Banashri hat geschrieben:Why builder?
In my opinion, it can be done using Command design pattern where invoker and receiver (3rd party application) are totally decoupled. Command is - DrawImage.
Correct me if I am wrong.
Maybe you are right, if you could provide more detail then it will be easy for me understand why command is suitable one for this.

Thanks !

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Re: Hiding the details

Beitrag von ayushmaan_jain »

junaidmohiuddin hat geschrieben:
I am really very Sorry i mean Bridge Pattern :)
Well by using the Bridge Pattern you can hide the implementation inside the abstraction .So in this way you can hide the implementation details from the client .
I am sorry but it's not making the sense to me why bridge pattern is suited for this design problem. Could you please give an example in the same context of problem.

Assax
Windoof-User
Windoof-User
Beiträge: 41
Registriert: 2. Dez 2011 10:38

Re: Hiding the details

Beitrag von Assax »

Maybe I am misunderstanding your question but isn't this exactly what the adapter pattern is for?

It is meant to adapt a third party interface in such a way that it is compatible to what you have and the client expects. Usually it is used in order to make a third party interface work with yours but I think you can also use it to hide that third party interface and use one of yours instead.

See this example given in the Design Patterns book:

http://i.imgur.com/mg1kKBu.png

In this case you want to draw shapes but drawing text is rather hard so you found a third party interface for that (TextView) and want to integrate it into your structure. You plug in an adapter that is used for communication between your interface and the third party. In this way the client can sill use the shape and define a textshape but all queries would actually just be forwarded to the third party without your client knowing any of it.

Banashri
Windoof-User
Windoof-User
Beiträge: 25
Registriert: 19. Dez 2013 02:55

Re: Hiding the details

Beitrag von Banashri »

Initially I thought of Adapter pattern. But the question states about hiding details of 3rd party library interface/classes. In Adapter, you adapt your existing interfaces/classes in order to use 3rd party libraries using Adapter.

Using Command pattern, you can use 3rd party libraries inside receiver objects. And invoker (whoever wants to call draw image command) does not know about implementation details of the command.

Assax
Windoof-User
Windoof-User
Beiträge: 41
Registriert: 2. Dez 2011 10:38

Re: Hiding the details

Beitrag von Assax »

Banashri hat geschrieben:But the question states about hiding details of 3rd party library interface/classes. In Adapter, you adapt your existing interfaces/classes in order to use 3rd party libraries using Adapter.
This still sounds the same to me =/ you want to hide details of 3rd party interface / class and adapting it gives you access to its functions without exposing it to the client.
Maybe you're right though and I just misunderstand :D Let's wait until the thread creator comes back.

junaidmohiuddin
Neuling
Neuling
Beiträge: 9
Registriert: 18. Jun 2015 13:05

Re: Hiding the details

Beitrag von junaidmohiuddin »

Banashri hat geschrieben: Using Command pattern, you can use 3rd party libraries inside receiver objects. And invoker (whoever wants to call draw image command) does not know about implementation details of the command.
If we use the Third Party Library inside the receiver object it will visible to the client .We need to hide the Third Party library right?
Correct me if i am wrong.

Regards
Junaid

Banashri
Windoof-User
Windoof-User
Beiträge: 25
Registriert: 19. Dez 2013 02:55

Re: Hiding the details

Beitrag von Banashri »

Client instantiates receiver object for the command object, which is to be set to invoker.
So, client does not know how the work is done by receiver.

ayushmaan_jain
Mausschubser
Mausschubser
Beiträge: 64
Registriert: 18. Okt 2014 11:11

Re: Hiding the details

Beitrag von ayushmaan_jain »

Thanks everyone for your reply. I tried applying all the patterns mentioned in this thread.
And what I found best suitable is Command Pattern.

Thanks everyone !

m.hosseinian
Windoof-User
Windoof-User
Beiträge: 34
Registriert: 3. Mai 2015 21:28

Re: Hiding the details

Beitrag von m.hosseinian »

Still, if you refer to the intents given for each DP, it's Adapter pattern that has the closest intent to this problem.

Antworten

Zurück zu „Archiv“