{"id":277,"date":"2023-10-03T21:17:52","date_gmt":"2023-10-03T19:17:52","guid":{"rendered":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/?page_id=277"},"modified":"2023-10-03T22:40:02","modified_gmt":"2023-10-03T20:40:02","slug":"adapter-2","status":"publish","type":"page","link":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/blog\/adapter-2\/","title":{"rendered":"Adapter"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"277\" class=\"elementor elementor-277\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-78286cf elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"78286cf\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b4ba983\" data-id=\"b4ba983\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e955604 elementor-widget elementor-widget-heading\" data-id=\"e955604\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<style>\/*! elementor - v3.18.0 - 20-12-2023 *\/\n.elementor-heading-title{padding:0;margin:0;line-height:1}.elementor-widget-heading .elementor-heading-title[class*=elementor-size-]>a{color:inherit;font-size:inherit;line-height:inherit}.elementor-widget-heading .elementor-heading-title.elementor-size-small{font-size:15px}.elementor-widget-heading .elementor-heading-title.elementor-size-medium{font-size:19px}.elementor-widget-heading .elementor-heading-title.elementor-size-large{font-size:29px}.elementor-widget-heading .elementor-heading-title.elementor-size-xl{font-size:39px}.elementor-widget-heading .elementor-heading-title.elementor-size-xxl{font-size:59px}<\/style><h2 class=\"elementor-heading-title elementor-size-default\">Adapter<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-02c1899 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"02c1899\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-59b7c6f\" data-id=\"59b7c6f\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7ca5fa4 elementor-position-right elementor-widget__width-initial elementor-vertical-align-top elementor-widget elementor-widget-image-box\" data-id=\"7ca5fa4\" data-element_type=\"widget\" data-widget_type=\"image-box.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<style>\/*! elementor - v3.18.0 - 20-12-2023 *\/\n.elementor-widget-image-box .elementor-image-box-content{width:100%}@media (min-width:768px){.elementor-widget-image-box.elementor-position-left .elementor-image-box-wrapper,.elementor-widget-image-box.elementor-position-right .elementor-image-box-wrapper{display:flex}.elementor-widget-image-box.elementor-position-right .elementor-image-box-wrapper{text-align:right;flex-direction:row-reverse}.elementor-widget-image-box.elementor-position-left .elementor-image-box-wrapper{text-align:left;flex-direction:row}.elementor-widget-image-box.elementor-position-top .elementor-image-box-img{margin:auto}.elementor-widget-image-box.elementor-vertical-align-top .elementor-image-box-wrapper{align-items:flex-start}.elementor-widget-image-box.elementor-vertical-align-middle .elementor-image-box-wrapper{align-items:center}.elementor-widget-image-box.elementor-vertical-align-bottom .elementor-image-box-wrapper{align-items:flex-end}}@media (max-width:767px){.elementor-widget-image-box .elementor-image-box-img{margin-left:auto!important;margin-right:auto!important;margin-bottom:15px}}.elementor-widget-image-box .elementor-image-box-img{display:inline-block}.elementor-widget-image-box .elementor-image-box-title a{color:inherit}.elementor-widget-image-box .elementor-image-box-wrapper{text-align:center}.elementor-widget-image-box .elementor-image-box-description{margin:0}<\/style><div class=\"elementor-image-box-wrapper\"><figure class=\"elementor-image-box-img\"><img decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapter-150x150.png\" class=\"attachment-thumbnail size-thumbnail wp-image-222\" alt=\"\" srcset=\"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapter-150x150.png 150w, https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapter-300x300.png 300w, https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapter.png 512w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/figure><div class=\"elementor-image-box-content\"><h3 class=\"elementor-image-box-title\">Do czego s\u0142u\u017cy wzorzec Adapter?<\/h3><p class=\"elementor-image-box-description\">Zaliczamy do wzorc\u00f3w strukturalnych. Dzi\u0119ki niemu, mo\u017cemy zmusi\u0107 do pracy dwa obiekty o niekompatybilnych interfejsach. Postaram si\u0119 wyt\u0142umaczy\u0107 ten wzorzec na przyk\u0142adzie p\u0142yty indukcyjnej i garnk\u00f3w, kt\u00f3re nie dzia\u0142aj\u0105 na p\u0142ycie indukcyjnej, czyli takich bez dna ferromagnetycznego. Jak wida\u0107 na pierwszy rzut oka, co\u015b jest nie tak. Garnki nie pasuj\u0105 do p\u0142yty, czy to znaczy \u017ce nic si\u0119 ju\u017c nie da zrobi\u0107 i trzeba kupi\u0107 nowe garnki? Ot\u00f3\u017c stosuj\u0105c adapter na p\u0142yt\u0119 indukcyjn\u0105, jeste\u015bmy w stanie u\u017cywa\u0107 wszystkich garnk\u00f3w, kt\u00f3re nie zosta\u0142y przystosowane na kuchenkach indukcyjnych. Tak samo dzia\u0142a wzorzec projektowy adapter.<\/p><\/div><\/div>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0c43666 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0c43666\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4086c21\" data-id=\"4086c21\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-23add8d elementor-position-left elementor-vertical-align-middle elementor-view-default elementor-mobile-position-top elementor-widget elementor-widget-icon-box\" data-id=\"23add8d\" data-element_type=\"widget\" data-widget_type=\"icon-box.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<link rel=\"stylesheet\" href=\"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/plugins\/elementor\/assets\/css\/widget-icon-box.min.css\">\t\t<div class=\"elementor-icon-box-wrapper\">\n\t\t\t\t\t\t<div class=\"elementor-icon-box-icon\">\n\t\t\t\t<span  class=\"elementor-icon elementor-animation-\">\n\t\t\t\t<i aria-hidden=\"true\" class=\"far fa-play-circle\"><\/i>\t\t\t\t<\/span>\n\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"elementor-icon-box-content\">\n\t\t\t\t<h3 class=\"elementor-icon-box-title\">\n\t\t\t\t\t<span  >\n\t\t\t\t\t\tinductionHob (PotWithoutFerromagnetic) ?\t\t\t\t\t<\/span>\n\t\t\t\t<\/h3>\n\t\t\t\t\t\t\t\t\t<p class=\"elementor-icon-box-description\">\n\t\t\t\t\t\tZacznijmy od uchwycenia problemu w kodzie. Poni\u017cej zamie\u015bci\u0142em klasy: InductionHob, GasStove, PotWithFerromagnetic, PotWithoutFerromagnatic. <br>\nJak wida\u0107 w poni\u017cszych klasach, garnki z ferromagnetykiem oraz garnki bez ferromagnetyka nagrzewaj\u0105 si\u0119 poprzez r\u00f3\u017cne systemy: inductionOn() lub burnerOn(). Stw\u00f3rzmy zatem demo do tego programu i zobaczmy czy garnek PotWithoutFerromagnetic zadzia\u0142a na p\u0142ycie indukcyjnej.\t\t\t\t\t<\/p>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-fe481f4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"fe481f4\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-288a8f5\" data-id=\"288a8f5\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-ba9ae2d elementor-tabs-alignment-stretch elementor-tabs-view-horizontal elementor-widget elementor-widget-tabs\" data-id=\"ba9ae2d\" data-element_type=\"widget\" data-widget_type=\"tabs.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<style>\/*! elementor - v3.18.0 - 20-12-2023 *\/\n.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tabs-wrapper{width:25%;flex-shrink:0}.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tab-desktop-title.elementor-active{border-right-style:none}.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tab-desktop-title.elementor-active:after,.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tab-desktop-title.elementor-active:before{height:999em;width:0;right:0;border-right-style:solid}.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tab-desktop-title.elementor-active:before{top:0;transform:translateY(-100%)}.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tab-desktop-title.elementor-active:after{top:100%}.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-desktop-title{display:table-cell}.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-desktop-title.elementor-active{border-bottom-style:none}.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-desktop-title.elementor-active:after,.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-desktop-title.elementor-active:before{bottom:0;height:0;width:999em;border-bottom-style:solid}.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-desktop-title.elementor-active:before{right:100%}.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-desktop-title.elementor-active:after{left:100%}.elementor-widget-tabs .elementor-tab-content,.elementor-widget-tabs .elementor-tab-title,.elementor-widget-tabs .elementor-tab-title:after,.elementor-widget-tabs .elementor-tab-title:before,.elementor-widget-tabs .elementor-tabs-content-wrapper{border:1px #d5d8dc}.elementor-widget-tabs .elementor-tabs{text-align:left}.elementor-widget-tabs .elementor-tabs-wrapper{overflow:hidden}.elementor-widget-tabs .elementor-tab-title{cursor:pointer;outline:var(--focus-outline,none)}.elementor-widget-tabs .elementor-tab-desktop-title{position:relative;padding:20px 25px;font-weight:700;line-height:1;border:solid transparent}.elementor-widget-tabs .elementor-tab-desktop-title.elementor-active{border-color:#d5d8dc}.elementor-widget-tabs .elementor-tab-desktop-title.elementor-active:after,.elementor-widget-tabs .elementor-tab-desktop-title.elementor-active:before{display:block;content:\"\";position:absolute}.elementor-widget-tabs .elementor-tab-desktop-title:focus-visible{border:1px solid #000}.elementor-widget-tabs .elementor-tab-mobile-title{padding:10px;cursor:pointer}.elementor-widget-tabs .elementor-tab-content{padding:20px;display:none}@media (max-width:767px){.elementor-tabs .elementor-tab-content,.elementor-tabs .elementor-tab-title{border-style:solid solid none}.elementor-tabs .elementor-tabs-wrapper{display:none}.elementor-tabs .elementor-tabs-content-wrapper{border-bottom-style:solid}.elementor-tabs .elementor-tab-content{padding:10px}}@media (min-width:768px){.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tabs{display:flex}.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tabs-wrapper{flex-direction:column}.elementor-widget-tabs.elementor-tabs-view-vertical .elementor-tabs-content-wrapper{flex-grow:1;border-style:solid solid solid none}.elementor-widget-tabs.elementor-tabs-view-horizontal .elementor-tab-content{border-style:none solid solid}.elementor-widget-tabs.elementor-tabs-alignment-center .elementor-tabs-wrapper,.elementor-widget-tabs.elementor-tabs-alignment-end .elementor-tabs-wrapper,.elementor-widget-tabs.elementor-tabs-alignment-stretch .elementor-tabs-wrapper{display:flex}.elementor-widget-tabs.elementor-tabs-alignment-center .elementor-tabs-wrapper{justify-content:center}.elementor-widget-tabs.elementor-tabs-alignment-end .elementor-tabs-wrapper{justify-content:flex-end}.elementor-widget-tabs.elementor-tabs-alignment-stretch.elementor-tabs-view-horizontal .elementor-tab-title{width:100%}.elementor-widget-tabs.elementor-tabs-alignment-stretch.elementor-tabs-view-vertical .elementor-tab-title{height:100%}.elementor-tabs .elementor-tab-mobile-title{display:none}}<\/style>\t\t<div class=\"elementor-tabs\">\n\t\t\t<div class=\"elementor-tabs-wrapper\" role=\"tablist\" >\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-1951\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"true\" data-tab=\"1\" role=\"tab\" tabindex=\"0\" aria-controls=\"elementor-tab-content-1951\" aria-expanded=\"false\">main.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-1952\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"2\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1952\" aria-expanded=\"false\">InductionHob.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-1953\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"3\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1953\" aria-expanded=\"false\">GasStove.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-1954\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"4\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1954\" aria-expanded=\"false\">PotWithFerromagnetic.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-1955\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"5\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1955\" aria-expanded=\"false\">PotWithoutFerromagnatic.java<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t\t<div class=\"elementor-tabs-content-wrapper\" role=\"tablist\" aria-orientation=\"vertical\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"true\" data-tab=\"1\" role=\"tab\" tabindex=\"0\" aria-controls=\"elementor-tab-content-1951\" aria-expanded=\"false\">main.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-1951\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-1951\" tabindex=\"0\" hidden=\"false\"><p>public class Main {<br \/>\u00a0\u00a0\u00a0 public static void main(String[] args) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PotWithoutFerromagnetic garnek = new PotWithoutFerromagnetic() {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void burnerOn() {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<em>out<\/em>.println(&#8222;Gotuj\u0119 si\u0119!&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };<br \/>\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0GasStove kuchenkaGazowa = new GasStove();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 kuchenkaGazowa.startCooking(garnek);\u00a0 \/\/dzia\u0142a: &#8222;Gotuj\u0119 si\u0119!&#8221;<br \/><br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 InductionHob plytaIndukcyjna = new InductionHob();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 plytaIndukcyjna.startCooking(garnek);\u00a0 \/\/ nie dzia\u0142a<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"2\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1952\" aria-expanded=\"false\">InductionHob.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-1952\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"2\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-1952\" tabindex=\"0\" hidden=\"hidden\"><p>public class InductionHob {<br \/>\u00a0\u00a0\u00a0 public void startCooking(PotWithFerromagnetic pot) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pot.inductionOn();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"3\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1953\" aria-expanded=\"false\">GasStove.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-1953\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"3\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-1953\" tabindex=\"0\" hidden=\"hidden\"><p>public class GasStove {<br \/>\u00a0\u00a0\u00a0 public void startCooking(PotWithoutFerromagnetic pot) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pot.burnerOn();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"4\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1954\" aria-expanded=\"false\">PotWithFerromagnetic.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-1954\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"4\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-1954\" tabindex=\"0\" hidden=\"hidden\"><p>public interface PotWithFerromagnetic {<br \/>\u00a0\u00a0\u00a0 void inductionOn();<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"5\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-1955\" aria-expanded=\"false\">PotWithoutFerromagnatic.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-1955\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"5\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-1955\" tabindex=\"0\" hidden=\"hidden\"><p>public interface PotWithoutFerromagnetic {<br \/>\u00a0\u00a0\u00a0 void burnerOn();<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7a389ce elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7a389ce\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6b49174\" data-id=\"6b49174\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2b2a747 elementor-position-right elementor-vertical-align-middle elementor-view-default elementor-mobile-position-top elementor-widget elementor-widget-icon-box\" data-id=\"2b2a747\" data-element_type=\"widget\" data-widget_type=\"icon-box.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-icon-box-wrapper\">\n\t\t\t\t\t\t<div class=\"elementor-icon-box-icon\">\n\t\t\t\t<span  class=\"elementor-icon elementor-animation-\">\n\t\t\t\t<i aria-hidden=\"true\" class=\"fab fa-gripfire\"><\/i>\t\t\t\t<\/span>\n\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"elementor-icon-box-content\">\n\t\t\t\t<h3 class=\"elementor-icon-box-title\">\n\t\t\t\t\t<span  >\n\t\t\t\t\t\tMission failed\t\t\t\t\t<\/span>\n\t\t\t\t<\/h3>\n\t\t\t\t\t\t\t\t\t<p class=\"elementor-icon-box-description\">\n\t\t\t\t\t\t\"java: incompatible types: patterns.adapter.PotWithoutFerromagnetic cannot be converted to patterns.adapter.PotWithFerromagnetic\", czyli przek\u0142adaj\u0105c na j\u0119zyk ludzki po prostu to nie zadzia\u0142a.<br>\nJe\u017celi staramy si\u0119 garnek bez ferromagnetyka zagotowa\u0107 na p\u0142ycie indukcyjnej to wyskakuje b\u0142\u0105d, program si\u0119 dzia\u0142a. Bez specjalnego adaptera nic nie zrobimy. Poka\u017c\u0119 teraz jak dzia\u0142a adapter.\t\t\t\t\t<\/p>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-51aafe2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"51aafe2\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ed90582\" data-id=\"ed90582\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-43cc7bf elementor-widget elementor-widget-heading\" data-id=\"43cc7bf\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Adapter - schemat dzia\u0142ania<\/h3>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ae1dfe0 elementor-widget__width-initial elementor-position-top elementor-widget elementor-widget-image-box\" data-id=\"ae1dfe0\" data-element_type=\"widget\" data-widget_type=\"image-box.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<div class=\"elementor-image-box-wrapper\"><figure class=\"elementor-image-box-img\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1678\" height=\"497\" src=\"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapterSchemat.png\" class=\"attachment-full size-full wp-image-257\" alt=\"\" srcset=\"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapterSchemat.png 1678w, https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapterSchemat-300x89.png 300w, https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapterSchemat-1024x303.png 1024w, https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapterSchemat-768x227.png 768w, https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/wp-content\/uploads\/2023\/10\/adapterSchemat-1536x455.png 1536w\" sizes=\"(max-width: 1678px) 100vw, 1678px\" \/><\/figure><div class=\"elementor-image-box-content\"><p class=\"elementor-image-box-description\">Aby podgrzewa\u0107 garnek bez ferromagnetyka na p\u0142ycie indukcyjnej zastosujemy adapter ForInductionAdapter. <br> <br>\nTeraz wystarczy tylko stworzy\u0107 w demo adapter i u\u017cy\u0107 go do nie pasuj\u0105cego garnka:<\/p><\/div><\/div>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4a16927 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4a16927\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c7bba41\" data-id=\"c7bba41\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e8cbfe7 elementor-tabs-alignment-stretch elementor-tabs-view-horizontal elementor-widget elementor-widget-tabs\" data-id=\"e8cbfe7\" data-element_type=\"widget\" data-widget_type=\"tabs.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-tabs\">\n\t\t\t<div class=\"elementor-tabs-wrapper\" role=\"tablist\" >\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-2441\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"true\" data-tab=\"1\" role=\"tab\" tabindex=\"0\" aria-controls=\"elementor-tab-content-2441\" aria-expanded=\"false\">main.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-2442\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"2\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2442\" aria-expanded=\"false\">InductionHob.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-2443\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"3\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2443\" aria-expanded=\"false\">GasStove.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-2444\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"4\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2444\" aria-expanded=\"false\">PotWithFerromagnetic.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-2445\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"5\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2445\" aria-expanded=\"false\">PotWithoutFerromagnatic.java<\/div>\n\t\t\t\t\t\t\t\t\t<div id=\"elementor-tab-title-2446\" class=\"elementor-tab-title elementor-tab-desktop-title\" aria-selected=\"false\" data-tab=\"6\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2446\" aria-expanded=\"false\">ForInductionAdapter.java<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t\t<div class=\"elementor-tabs-content-wrapper\" role=\"tablist\" aria-orientation=\"vertical\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"true\" data-tab=\"1\" role=\"tab\" tabindex=\"0\" aria-controls=\"elementor-tab-content-2441\" aria-expanded=\"false\">main.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-2441\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-2441\" tabindex=\"0\" hidden=\"false\"><p>public class Main {<br \/>\u00a0\u00a0\u00a0 public static void main(String[] args) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PotWithoutFerromagnetic garnek = new PotWithoutFerromagnetic() {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void burnerOn() {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<em>out<\/em>.println(&#8222;Gotuj\u0119 si\u0119!&#8221;);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 GasStove kuchenkaGazowa = new GasStove();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 kuchenkaGazowa.startCooking(garnek); \/\/dzia\u0142a: &#8222;Gotuj\u0119 si\u0119!&#8221;<br \/><br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 InductionHob plytaIndukcyjna = new InductionHob();<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ForInductionAdapter adapter = new ForInductionAdapter(garnek);<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 plytaIndukcyjna.startCooking(adapter); \/\/dzia\u0142a: &#8222;Gotuj\u0119 si\u0119!&#8221;<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"2\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2442\" aria-expanded=\"false\">InductionHob.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-2442\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"2\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-2442\" tabindex=\"0\" hidden=\"hidden\"><p>public class InductionHob {<br \/>\u00a0\u00a0\u00a0 public void startCooking(PotWithFerromagnetic pot) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pot.inductionOn();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"3\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2443\" aria-expanded=\"false\">GasStove.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-2443\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"3\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-2443\" tabindex=\"0\" hidden=\"hidden\"><p>public class GasStove {<br \/>\u00a0\u00a0\u00a0 public void startCooking(PotWithoutFerromagnetic pot) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pot.burnerOn();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"4\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2444\" aria-expanded=\"false\">PotWithFerromagnetic.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-2444\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"4\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-2444\" tabindex=\"0\" hidden=\"hidden\"><p>public interface PotWithFerromagnetic {<br \/>\u00a0\u00a0\u00a0 void inductionOn();<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"5\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2445\" aria-expanded=\"false\">PotWithoutFerromagnatic.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-2445\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"5\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-2445\" tabindex=\"0\" hidden=\"hidden\"><p>public interface PotWithoutFerromagnetic {<br \/>\u00a0\u00a0\u00a0 void burnerOn();<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-tab-title elementor-tab-mobile-title\" aria-selected=\"false\" data-tab=\"6\" role=\"tab\" tabindex=\"-1\" aria-controls=\"elementor-tab-content-2446\" aria-expanded=\"false\">ForInductionAdapter.java<\/div>\n\t\t\t\t\t<div id=\"elementor-tab-content-2446\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"6\" role=\"tabpanel\" aria-labelledby=\"elementor-tab-title-2446\" tabindex=\"0\" hidden=\"hidden\"><p>public class ForInductionAdapter implements PotWithFerromagnetic{<br \/>\u00a0\u00a0\u00a0 PotWithoutFerromagnetic pot;<br \/>\u00a0\u00a0\u00a0 public ForInductionAdapter(PotWithoutFerromagnetic pot) {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 this.pot = pot;<br \/>\u00a0\u00a0\u00a0 }<br \/>\u00a0\u00a0\u00a0 @Override<br \/>\u00a0\u00a0\u00a0 public void inductionOn() {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pot.burnerOn();<br \/>\u00a0\u00a0\u00a0 }<br \/>}<\/p><\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0942410 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0942410\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8fbd545\" data-id=\"8fbd545\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-89ba701 elementor-position-right elementor-vertical-align-middle elementor-view-default elementor-mobile-position-top elementor-widget elementor-widget-icon-box\" data-id=\"89ba701\" data-element_type=\"widget\" data-widget_type=\"icon-box.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-icon-box-wrapper\">\n\t\t\t\t\t\t<div class=\"elementor-icon-box-icon\">\n\t\t\t\t<span  class=\"elementor-icon elementor-animation-\">\n\t\t\t\t<i aria-hidden=\"true\" class=\"fas fa-lightbulb\"><\/i>\t\t\t\t<\/span>\n\t\t\t<\/div>\n\t\t\t\t\t\t<div class=\"elementor-icon-box-content\">\n\t\t\t\t<h3 class=\"elementor-icon-box-title\">\n\t\t\t\t\t<span  >\n\t\t\t\t\t\tPodsumowanie\t\t\t\t\t<\/span>\n\t\t\t\t<\/h3>\n\t\t\t\t\t\t\t\t\t<p class=\"elementor-icon-box-description\">\n\t\t\t\t\t\tTo wszystko powy\u017cej to podstawowa implementacja wzorca adapter. Mo\u017cna spotka\u0107 si\u0119 jeszcze z adapterem dwukierunkowym, kt\u00f3ry za po\u015brednictwem jednej klasy adaptera, m\u00f3g\u0142by dzia\u0142a\u0107 dwukierunkowo, tzn. \u0142\u0105czy\u0107 garnek bez ferromagnetyka z p\u0142yt\u0105 indukcyjn\u0105 oraz \u0142\u0105czy\u0107 garnek z ferromagnetykiem z kuchenk\u0105 gazow\u0105. <br>Najwi\u0119ksz\u0105 wad\u0105 adaptera jest to, \u017ce dodaje dodatkowy poziom abstrakcji mi\u0119dzy naszymi komponentami. Pomimo swoich wad wzorzec adapter jest cz\u0119sto u\u017cywanym wzorcem.\t\t\t\t\t<\/p>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Adapter Do czego s\u0142u\u017cy wzorzec Adapter? Zaliczamy do wzorc\u00f3w strukturalnych. Dzi\u0119ki niemu, mo\u017cemy zmusi\u0107 do pracy dwa obiekty o niekompatybilnych interfejsach. Postaram si\u0119 wyt\u0142umaczy\u0107 ten wzorzec na przyk\u0142adzie p\u0142yty indukcyjnej i garnk\u00f3w, kt\u00f3re nie dzia\u0142aj\u0105 na p\u0142ycie indukcyjnej, czyli takich bez dna ferromagnetycznego. Jak wida\u0107 na pierwszy rzut oka, co\u015b jest nie tak. Garnki nie [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":154,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-277","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/pages\/277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/comments?post=277"}],"version-history":[{"count":14,"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/pages\/277\/revisions"}],"predecessor-version":[{"id":318,"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/pages\/277\/revisions\/318"}],"up":[{"embeddable":true,"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/pages\/154"}],"wp:attachment":[{"href":"https:\/\/pawel-majchrzak.profesjonalnyprogramista.pl\/index.php\/wp-json\/wp\/v2\/media?parent=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}