ooad

How do I use composition with inheritance?

元气小坏坏 提交于 2019-12-03 08:16:36
I'm going to try to ask my question in the context of a simple example... Let's say I have an abstract base class Car. Car has-a basic Engine object. I have a method StartEngine() in the abstract Car class that delegates the starting of the engine to the Engine object. How do I allow subclasses of Car (like Ferrari) to declare the Engine object as a specific type of engine (e.g., TurboEngine)? Do I need another Car class (TurboCar)? I'm inheriting a plain old Engine object and I cannot re-declare (or override) it as a TurboEngine in my Car subclasses. EDIT: I understand that I can plug any

How to avoid getters and setters

荒凉一梦 提交于 2019-12-03 03:11:44
问题 I have read in many places that "getters and setters are evil". And I understood why so. But I don't know how to avoid them completely. Say Item is a class that has information about item name, qty, price etc... and ItemList is a class, which has a list of Items. To find the grand total: int grandTotal() { int total = 0; for (Item item: itemList) total += item.getPrice(); return total; } In the above case, how does one avoid getPrice()? The Item class provides getName, setName, etc.... How do

C++ : Association, Aggregation and Composition

微笑、不失礼 提交于 2019-12-03 02:01:59
问题 I'm beginning to study OOAD and I'm having difficulty finding a C++ code example that'd illustrate how Association , Aggregation and Composition are implemented programmatically. (There are several posts everywhere but they relate to C# or java). I did find an example or two, but they all conflict with my instructor's instructions and I'm confused. My understanding is that in: Association: Foo has a pointer to Bar object as a data member Aggregation: Foo has a pointer to Bar object and data

OOAD book recommendation: from theory to practice [closed]

╄→гoц情女王★ 提交于 2019-12-03 01:23:28
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I am on the quest to be a good OO-developer. OO intrigues me, because I understand the patterns, know why composition gives you more flexibility then inheritance, and more of such wisdom. However, I came to the conclusion that I know how to implement a factory of a singleton, but that I do not know how to come

How to avoid getters and setters

Deadly 提交于 2019-12-02 16:41:29
I have read in many places that "getters and setters are evil". And I understood why so. But I don't know how to avoid them completely. Say Item is a class that has information about item name, qty, price etc... and ItemList is a class, which has a list of Items. To find the grand total: int grandTotal() { int total = 0; for (Item item: itemList) total += item.getPrice(); return total; } In the above case, how does one avoid getPrice()? The Item class provides getName, setName, etc.... How do I avoid them? Jonathan Fingland When should you use getters and setters? Getters and setters are great

C++ : Association, Aggregation and Composition

回眸只為那壹抹淺笑 提交于 2019-12-02 15:38:24
I'm beginning to study OOAD and I'm having difficulty finding a C++ code example that'd illustrate how Association , Aggregation and Composition are implemented programmatically. (There are several posts everywhere but they relate to C# or java). I did find an example or two, but they all conflict with my instructor's instructions and I'm confused. My understanding is that in: Association: Foo has a pointer to Bar object as a data member Aggregation: Foo has a pointer to Bar object and data of Bar is deep copied in that pointer. Composition: Foo has a Bar object as data member. And this is how

OOAD Design issue

半腔热情 提交于 2019-12-02 14:58:15
问题 I have two tables: tblCustomer , tblProduct : tblCustomer: Id: Integer, auto-increament Name: Varchar(30) .... tblProduct Id: Integer, auto-increament Name: Varchar(50) customerId: Integer .... And two classes: Customer , Product : public class Product { private int id; private int name; /* Other stuffs */ } public class Customer { private int id; private String name; private String phoneNumber; /* get-set and others stuffs */ public static boolean add(Customer cus) { /* This is for insert a

OOAD book recommendation: from theory to practice [closed]

懵懂的女人 提交于 2019-12-02 14:45:17
I am on the quest to be a good OO-developer. OO intrigues me, because I understand the patterns, know why composition gives you more flexibility then inheritance, and more of such wisdom. However, I came to the conclusion that I know how to implement a factory of a singleton, but that I do not know how to come up with a robust OO design . I have a bunch of books Design Patterns by the GoF AntiPatterns Brown et al. Refactoring by Fowler Code complete 2 They might be very good books, but they don't teach you to architect an application. I am often paralysed by some very basic decisions ( example

OOAD Design issue

与世无争的帅哥 提交于 2019-12-02 10:01:39
I have two tables: tblCustomer , tblProduct : tblCustomer: Id: Integer, auto-increament Name: Varchar(30) .... tblProduct Id: Integer, auto-increament Name: Varchar(50) customerId: Integer .... And two classes: Customer , Product : public class Product { private int id; private int name; /* Other stuffs */ } public class Customer { private int id; private String name; private String phoneNumber; /* get-set and others stuffs */ public static boolean add(Customer cus) { /* This is for insert a customer to tblCustomer */ } public boolean addProduct(Product pd) { /* This is for insert a product to

What is the difference between composition and aggregation? [duplicate]

Deadly 提交于 2019-12-01 21:25:09
问题 This question already has answers here : Closed 10 years ago . What is the difference between composition and aggregation? can anybody give me a sample of this OOAD? 回答1: Found here "Both aggregation and composition are special kinds of associations. Aggregation is used to represent ownership or a whole/part relationship, and composition is used to represent an even stronger form of ownership. With composition, we get coincident lifetime of part with the whole. The composite object has sole