Results (
Indonesian) 1:
[Copy]Copied!
Solusi menetapkan kelas B tanggung jawab untuk menciptakan instance kelas A jika satu atau lebih dari Berikut ini benar:ï B agregat A objek. ï B berisi objek. ï B mencatat contoh-contoh dari objek. ï B erat menggunakan A objek. ï B memiliki data initializing yang akan dilewatkan ke A ketika itu diciptakan (dengan demikian B adalah seorang ahli sehubungan dengan menciptakan A). B adalah pencipta objek.Jika lebih dari satu pilihan berlaku, memilih kelas B yang agregator atau berisi kelas A.Masalah yang harus bertanggung jawab untuk membuat sebuah instance baru dari beberapa kelas?Penciptaan benda adalah salah satu kegiatan yang paling umum dalam berorientasi objek sistem. Akibatnya, hal ini berguna untuk memiliki prinsip umum untuk tugas penciptaan tanggung jawab. Ditetapkan baik, desain dapat mendukung rendah coupling, meningkatkan kejelasan, enkapsulasi, dan usabilitasContoh di POS aplikasi, yang harus bertanggung jawab untuk menciptakan SalesLineltem contoh? Oleh pencipta, kita harus melihat untuk sebuah kelas yang agregator, berisi, dan begitu pada, contoh-contoh SalesLineltem. Mempertimbangkan model parsial domain dalam gambar 16,7Karena Sate berisi (pada kenyataannya, agregat) banyak SalesLineltem objek, pencipta pola menunjukkan bahwa penjualan adalah calon yang baik untuk memiliki tanggung jawab membuat contoh SalesLineltem.Ini mengarah ke sebuah desain interaksi objek seperti ditunjukkan pada gambar 16,8Tugas ini tanggung jawab memerlukan makeLineltem metode agar defined in Sate.Once again, the context in which these responsibilities were considered and decided upon was while drawing an interaction diagram. The method section of a class diagram can then summarize the responsibility assignment results, concretely realized as methods.Discussion Creator guides assigning responsibilities related to the creation of objects, a very common task. The basic intent of the Creator pattern is to find a creator that needs to be connected to the created object in any event. Choosing it as the creator supports low coupling.Aggregate aggregates Part, Container contains Content, and Recorder records Recorded are all very common relationships between classes in a class diagram. Creator suggests that the enclosing container or recorder class is a good candidate for the responsibility of creating the thing contained or recorded. Of course, this is only a guideline.Note that the concept of aggregation has been used in considering the Creator pattern. Aggregation is discussed in Chapter 27; a brief definition is that aggregation involves things that are in a strong Whole-Part or Assembly-Part relationship, such as Body aggregates Leg or Paragraph aggregates Sentence.Sometimes a creator is found by looking for the class that has the initializing data that will be passed in during creation. This is actually an example of the Expert pattern. Initializing data is passed in during creation via some kind of initialization method, such as a Java constructor that has parameters. For example, assume that a Payment instance needs to be initialized, when created, with the Sale total. Since Sale knows the total, Sale is a candidate creator of the Payment.Contraindications Often, creation requires significant complexity, such as using recycled instances for performance reasons, conditionally creating an instance from one of a family of similar classes based upon some external property value, and so forth. In these cases, it is advisable to delegate creation to a helper class called a Factory [GHJV95] rather than use the class suggested by Creator. Factories are discussed in Chapter 23.BenefitsRelated Patterns or PrinciplesLow coupling (described next) is supported, which implies lower maintenance dependencies and higher opportunities for reuse. Coupling is probably not increased because the created class is likely already visible to the creator class, due to the existing associations that motivated its choice as creator.Low Coupling FactoryWhole-Part [BMRSS96] describes a pattern to define aggregate objects that support encapsulation of components.
Being translated, please wait..
