Ex 06 Task 1

dummdidumm
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 28. Apr 2010 18:49

Ex 06 Task 1

Beitrag von dummdidumm »

I don't understand what to do in task 1, especially subtask 1. It says we should provide a design so that all operations are freely combinable. I assume with operations you mean "add", "mult" and possible future operations. The operations in the current design are freely combinable, you can put any type of expression into add/mult. Also, the abstract classes Expr and BinExpr provide implementations for "pretty printing" and "optimizing". So what exactly do we have to do? Also, the sentence "Create a base class, which contains necessary logic to create and evaluate expressions" confuses me. What exactly is meant with "create expressions"?

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: Ex 06 Task 1

Beitrag von #14 »

i was just about to ask the same question.

please give examples of how the new design should work differently, as the current design already enables the free combination of operations.

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 06 Task 1

Beitrag von sproksch »

An example of how to create an expression is supplied as a test. To create an expression you just have to combine several Variable, Constants or Expressions. Perhaps I should have better said: "... to create a statement and be able to evaluate it."

You are right, "formatting" and "optimizing" are two features that are already implemented. As they are not necessarily needed when working with expressions, they should be removed from the base class and moved to inherited classes that extend the current class hierarchy. You should do this in a way that allows the developer to freely combine such features as they are needed.

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: Ex 06 Task 1

Beitrag von #14 »

so the basic class structure should remain as given, but the two features "format" and "optimize" should become external. is that correct?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 06 Task 1

Beitrag von sproksch »

Yes, "external" in the sense of "extended through inheritance" (e.g, a FormattedAdd).

edit: edited to remove misleading name

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: Ex 06 Task 1

Beitrag von #14 »

it isn't actually any necessary and rather over-engineered to be doing this with two extensions, is it?!

#14
Mausschubser
Mausschubser
Beiträge: 80
Registriert: 7. Dez 2007 13:54
Wohnort: Darmstadt

Re: Ex 06 Task 1

Beitrag von #14 »

i've been trying to solve this without any abstract methods for pretty printing or optimizing in the base classes and also without any type casting in the extension.. is that actually possible?

dummdidumm
Windoof-User
Windoof-User
Beiträge: 39
Registriert: 28. Apr 2010 18:49

Re: Ex 06 Task 1

Beitrag von dummdidumm »

Ok, after looking through the pattern-slides, i know what the tasks actually wants us to do :)

But i still have some questions:
1. "Only based on inheritance" - does this mean we also cannot use interfaces and implement them? Only "x extends y"?
2. Again on the "create expressions"-sentence. I still don't know what exactly is meant. Should we provide methods like "public Expr makeAdd(Expr1, Expr2)" which creates an add-operation with given expressions and returns the resulting expression?

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 06 Task 1

Beitrag von sproksch »

No, everything you should do is to provide a way to create statements like "(4 + 2) * a" to work with them afterwards... You do not need to implement a parser for this, it is ok if you can create the expressions programmatically (as I said, look at the existing test for an example).

xAx
Endlosschleifenbastler
Endlosschleifenbastler
Beiträge: 157
Registriert: 6. Mär 2008 17:20

Re: Ex 06 Task 1

Beitrag von xAx »

Are we allowed to use the visitor pattern? It needs an accept method, but the task seems to strictly require only to use inheritance. :cry:
Nichts ist wie es scheint!
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Zuletzt geändert von xAx am 14. Mär 2009 16:17, insgesamt 99-mal geändert.

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 06 Task 1

Beitrag von sproksch »

Ok, I discussed the exercise with a student and obviously my formulation is the cause for all this confusion. So lets try another formulation for the exercise task:
future me hat geschrieben:Together with the exercise sheet, a project was published that contains an application, which can be used to evaluate simple arithmetic expressions. The elements of the type hierarchy in the project contain three methods at the moment:

- eval() can be used to evaluate an expression.
- format() can be used to “pretty print” an expression.
- optimize() can be used to simplify expressions.

The given classes in the hierarchy combine three concerns, which shouldn't be mixed: evaluating of expressions, printing of expressions and simplification of expressions. Tasks for this exercise:

1. Refactor the example and create a design that separates these concerns into separate classes: Create a base hierarchy that allows creating and evaluating of expressions. Create two extensions to this hierarchy that enable the features “pretty printing” and “simplification”. Do not make use of composition to achieve this; your solution should only be based on inheritance. Implement your design. (2P)
2. Create a UML class diagram that reflects your altered design. (1P)
3. Identify problems of the design: Think about possible runtime exceptions or how different features can be combined. (1P)

Commit all results of this task to your repository.
Regarding the visitor pattern... the task is named "Limitations of variability through inheritance", so no, you are not allowed to use the visitor pattern. As already stated, "Your solution should only be based on inheritance".

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 06 Task 1

Beitrag von sproksch »

Btw.: If you think this is a bad design decision... perhaps you want to use your arguments to answer subtask 3.

[-=thomas=-]
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 137
Registriert: 27. Apr 2009 10:47
Wohnort: Darmstadt

Re: Ex 06 Task 1

Beitrag von [-=thomas=-] »

#14 hat geschrieben:it isn't actually any necessary and rather over-engineered to be doing this with two extensions, is it?!
I definitely agree. But after I read the reformulated task, I also think that it is not solvable without "combining" and "instanceof-cascades" for the binary expressions. Or I completely missed the point of what Sebastian was trying to say :?

What would be an example of how the new design would be used? I couldn't think of any other possibility than wrapping around some "pretty"- or "opt"-class.
Tutor:
WS 11/12: FGdI 3, FoC
SS 11: CMS

Benutzeravatar
sproksch
Computerversteher
Computerversteher
Beiträge: 346
Registriert: 15. Apr 2004 17:56

Re: Ex 06 Task 1

Beitrag von sproksch »

Sorry, but I have no clue how to give you more hints without giving the solution. I suppose you are thinking in a more complicated way than it is actually needed... does it help if I say that there are two possible alternatives to solve this task?

[-=thomas=-]
BASIC-Programmierer
BASIC-Programmierer
Beiträge: 137
Registriert: 27. Apr 2009 10:47
Wohnort: Darmstadt

Re: Ex 06 Task 1

Beitrag von [-=thomas=-] »

sproksch hat geschrieben:does it help if I say that there are two possible alternatives to solve this task?
Surprisingly, yep
Tutor:
WS 11/12: FGdI 3, FoC
SS 11: CMS

Antworten

Zurück zu „Archiv“